You are here

Tutorial : compile a C/GTK+3 program with MinGW under Windows

Objectives : compile a C/GTK+3 source code with MinGW, using the official bundle.

As the GTK+ 3 Windows binaries now have an official distribution, you may want to use them to start a development from scratch, or port an existing UNIX project to Windows.

In the first case, you have the choice between MinGW (the Windows port of GNU's GCC) or Microsoft Visual C++. In the second case, you're likely to choose MinGW as many UNIX build facilities expect to find and use it.

We'll now suppose you have a vanilla Win32 box, with nothing particular installed, and see how to rapidly setup a working MinGW/C/GTK+3 build environment.

1) Install MinGW

a) Download the MinGW Setup Tool (84,5 Kb).

b) Double-click on it :

(don't change the default install path which should be "C:\MinGW")

c) Check at least the mingw-developer-toolkit, mingw32-base and msys-base packages :

d) Open the Installation menu and choose Apply Changes :

It will ask you for confirmation and take some time to download everything.

2) Install GTK+3

a) Download the latest all-in-one bundle ZIP archive directly from the official website (here's a direct link for impatients...).

b) Right-click on it, choose Extract all... :

and extract it to C:\MinGW as installed before :

(if it asks about existing files, always choose to overwrite :


c) There's an additional step which may be required under some versions of Windows 7-8 :
Open a console (Start -> Run -> "cmd" or Start -> search for "cmd") and type :
mklink /d c:\MinGW\msys\1.0\mingw c:\MinGW

3) Compile

We are now ready to compile some code.

a) Run the MSYS environment (an UNIX terminal mockup session, using Bash and several other GNU tools) by going to "C:\MinGW\msys\1.0" and double-clicking on msys.bat :

b) A MSYS console window opens. In it, you're located in the "C:\MinGW\msys\1.0\home\username" directory, where username is the Windows account you're currently using. Copy-paste your source code to this folder.

c) In the MSYS console window, build your code by running a standard GCC/GTK+3 compile command, like :
gcc source.c -o executable.exe `pkg-config --cflags --libs gtk+-3.0`

Here we go !


I'd just like to point out that the command for Step 3 part c is incorrect. You have 'libs gtk+-.3.0' while in the screenshot, you have libs gtk+-3.0
There is to be no '.' before the 3.

Fixed ; thanks.

its giveing following err
"gcc comand not found"

gcc is in the "mingw32-base" package which is supposed to be installed in the 1st part of the tutorial. If you dont' have it, then something went wrong during this phase. Try to reinstall it.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.