How to use GTK+ on Windows

For developers who are familiar with Linux or another open source framework, this issue seems to be nothing to say. However, with a stranger like me, that is really a big problem and takes much time of mine. That is the reason of this post that aims to aggregate, share my experiences and give you a quick step on getting started with GTK+ on Windows.

What is GTK+?

GTK+, or the GIMP Toolkit, is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets,GTK+ is suitable for projects ranging from small one-off tools to complete application suites.

Source gtk

GTK+ Installation Guide

First, you need to download GTK+ at here. You have the choice on downloading individual packages or all-in-one bundle. I recommend all-in-one bundle since it is more convenient and faster.

Then, follow to wizard to install GTK+ and you need a cup of coffee :D.

For more information about GTK+, click here.

What need?

Maybe, you can use another tools, but I have used the following ones:

  1. MinGW
  2. MSYS

What is MinGW?

MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications.

Source MinGW

Why do we need MinGW?

To compile your source code on C, C++,… I tried to do that by Borland C (with a need on including some libraries) but at the moment, I still have not done yet. So it will be easier for you if using gcc on MinGW.

MinGW Installation Guide

This work is quite simple. Just download the above installer, follow the wizard until finishing. If you want to learn more, click here.

For more information about MinGW, click here.

What is MSYS?

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

Source MSYS

Why do we need MSYS?

Let’s try to compile your source code by Command Prompt (cmd) of Windows (presumably GTK+ and MinGW are installed) – gcc -o simple simple.c `pkg-config –libs –cflags gtk+-2.0`. Are there some problems? I guess that cmd does not completely support the syntax like that, especially `pkg-config –libs –cflags gtk+-2.0`, so some errors occur. Once again, to make life easier, instead of cmd, we use MSYS.

MSYS Installation Guide

Similar to MinGW, MSYS installation is simple too. There is just one note that when being asked the path of MinGW, you need to enter it (C:\MinGW as default). If you want to learn more, click here.

For more information about MSYS, click here.

After done all of above things, you still need one more work that is setting PATH environment variable to c:\MinGW\bin;c:\gtk\bin (use appropriate paths if you do not use the default).


There is no blank space between the semicolon (;) and the next path (c:\gtk\bin).

Now, you are ready to work with GTK+. Congratulate!

Let’s begin with the simplest sample, show the basic window.


int main( int argc, char *argv[])
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_show(window);  gtk_main();  return 0;

Save it as sample.c then compile it

gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`

Enjoy your result 😀


There is difference between .c and .cpp. Unlike Borland C, if you use .cpp, you need to ensure that the C++ compiler have installed at MinGW installation phase and use g++ instead of gcc on command.



Tags: , , , , , , , ,

About ninjapro

It is better to feel by yourself about me

2 responses to “How to use GTK+ on Windows”

  1. overlord290131 says :

    Why don’t you install a Linux distro and work on it? Must be easier

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: