Tutorial : cross-compile a C/GTK+3 program from Linux to Windows

As the GTK+ 3 Windows binaries now have an official distribution, we will be able to use to create a Windows version of our application, without modifiying the source code nor having a Windows box available.

(ps : Create a folder named "gtk3-win32" where you want, put the ZIP archive therein and extract it with :unzip gtk+-bundle_3.6.4-20130921_win32.zip)

- Adapt GTK+ to its location :
In a terminal, move to the "gtk3-win32" folder you just created. If you extracted it to "/opt/gtk3-win32" e.g. :cd /opt/gtk3-win32
then do :find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$PWD@" -i "$pc"; done

2) Compile

- We will tell "pkg-config" to locate GTK+ libraries in our custom path. If you extracted to "/opt/gtk3-win32" e.g. :export PKG_CONFIG_PATH=/opt/gtk3-win32/lib/pkgconfig

We are ready to compile an sample C source ! Let's use a command in this style :

Comments

Thanks for posting this hint. I'd never thought of modifying the .pc files with an sed script. I'm working on a cross compiled Gtk3 project where that turns out to be a very useful addition to the toolbox. If you could provide a link to your gtk test program source, it would save some folks some effort. On my Ubuntu 13.10 (x86_64) system the compiler is 'i686-w64-mingw32-gcc' . Even more importantly, the test program I compiled runs well using Wine.

I followed your tut step by step. Everthing seems to be so smooth but in during comilation i got this compiler error:

#$ i586-mingw32msvc-gcc /home/spivvi/Desktop/test.c -o test.exe `pkg-config --cflags --libs gtk+-3.0`
i586-mingw32msvc-gcc: unrecognized option '-pthread'
In file included from /usr/include/glib-2.0/glib.h:108,
from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
from /usr/include/gtk-3.0/gdk/gdk.h:30,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from /home/spivvi/Desktop/test.c:1:
/usr/include/glib-2.0/glib/deprecated/gthread.h:123:21: error: pthread.h: No such file or directory
In file included from /usr/include/glib-2.0/glib.h:108,
from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
from /usr/include/gtk-3.0/gdk/gdk.h:30,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from /home/spivvi/Desktop/test.c:1:
/usr/include/glib-2.0/glib/deprecated/gthread.h:133: error: expected specifier-qualifier-list before ‘pthread_mutex_t’
/usr/include/glib-2.0/glib/deprecated/gthread.h:162: error: expected specifier-qualifier-list before ‘pthread_t’
In file included from /usr/include/glib-2.0/gio/gio.h:47,
from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from /home/spivvi/Desktop/test.c:1: