The application needs to be compiled using MinGW and not Cygwin.
The full list of steps I followed:
1) Download MinGW
2) Install MinGW to a folder without spaces, e.g. to c:MinGW.
3) Download gtk+. Even though my machine is 64bit, I went for the 32 bit download of gtk+ because compatibility warnings on the 64bit download page. The GTK+ Win32 downloads are here. I went for the all-in-one version.
4) Extract gtk+ to a folder without spaces, e.g. c:gtk
5) If you don't already have an application, you can use the gtk+ hello world source code. Save this to a folder, e.g. c:myapp
6) Open a windows command prompt and cd to the folder in step 5. E.g.
cd c:myapp
7) In the command window, add your MinGW folder to the windows PATH, e.g.
c:myapp> set PATH=c:gtkin;%PATH%
8) In the command window, add your gtk+ folder to the windows PATH, e.g.
c:myapp> set PATH=c:gtkin;%PATH%
9) Create a script to compile your application, e.g.
C:myapp> C:MinGWmsys1.0inash.exe -c "echo gcc -Wall -g helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` > compile.bat"
Note that I had to give the full path to bash.exe. For some reason adding c:MinGWmsys1.0in
to the PATH and just using bash.exe
didn't work for me.
10) compile your application with compile.bat, e.g.
c:myapp> compile.bat
12) execute your application, e.g.
c:myapp> helloworld.exe
EDIT:
For step 9, we are just creating a gcc
command to compile gtk+ with the correct include and library option settings.
This is the contents of compile.bat
that got generated for me:
gcc -Wall -g helloworld.c -o helloworld -mms-bitfields -Ic:/DEV/gtk224/include/gtk-2.0 -Ic:/DEV/gtk224/lib/gtk-2.0/include -Ic:/DEV/gtk224/include/atk-1.0 -Ic:/DEV/gtk224/include/cairo -Ic:/DEV/gtk224/include/gdk-pixbuf-2.0 -Ic:/DEV/gtk224/include/pango-1.0 -Ic:/DEV/gtk224/include/glib-2.0 -Ic:/DEV/gtk224/lib/glib-2.0/include -Ic:/DEV/gtk224/include -Ic:/DEV/gtk224/include/freetype2 -Ic:/DEV/gtk224/include/libpng14 -Lc:/DEV/gtk224/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
Of which, the include options created by pkg-config --cflags gtk+-2.0
:
-mms-bitfields -Ic:/DEV/gtk224/include/gtk-2.0 -Ic:/DEV/gtk224/lib/gtk-2.0/include
-Ic:/DEV/gtk224/include/atk-1.0 -Ic:/DEV/gtk224/include/cairo
-Ic:/DEV/gtk224/include/gdk-pixbuf-2.0 -Ic:/DEV/gtk224/include/pango-1.0
-Ic:/DEV/gtk224/include/glib-2.0 -Ic:/DEV/gtk224/lib/glib-2.0/include
-Ic:/DEV/gtk224/include -Ic:/DEV/gtk224/include/freetype2
-Ic:/DEV/gtk224/include/libpng14
(note I have put in line breaks above to improve readability on stackoverflow)
Notice that pkg-config --cflags gtk+-2.0
has put the full path of my gtk+ include files (c:/DEV/gtk224/include/).
And the library options generated by pkg-config --libs gtk+-2.0
:
-Lc:/DEV/gtk224/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0
-lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0
-lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
(note I have put in line breaks above to improve readability on stackoverflow)
Notice that pkg-config --libs gtk+-2.0
has put the full path of my gtk library folder (c:/DEV/gtk224/lib).
For more information on pkg-config
see the GTK+ documentation