How to guide for cross-compiling GTK+ for Win32

This is intended to be a quick-start guide for building GTK+ binaries for Win32, but from the comfort of Linux.


To begin, you'll need to install mingw, the Linux/UNIX Win32 cross compiler. It allows you to build binaries for the Windows platform using a Linux box. Note you should also uninstall the Wine headers, because they cause nasty conficts with mingw's ones while compiling.

MinGW Installation instructions




  apt-get install mingw32 mingw32-binutils mingw32-runtime 

Follow the instructions on this page.

 emerge xmingw xmingw 

Wine headers Uninstallation




  apt-get remove wine-dev 

Building the sources using Jhbuild

First, follow the instructions to install Jhbuild. Then download the archive jhbuild.mingw.gtk-2.16.tgz and extract it to a directory of your choice.

tar xzf jhbuild.mingw.gtk-2.16.tgz

You will get a new subdirectory jhbuild.mingw.gtk-2.16. Make this directory your working directory

cd jhbuild.mingw.gtk-2.16

and call


to build a debug version or


to build a release version of GTK+. These are simple shell scripts which call jhbuild with a suitable jhbuildrc file. Any arguments will be passed to jhbuild.

The dowloads and builds will be done in the subdirectory checkout.dbg or checkout.rls depending on the shell script called. The resulting files for installation will be placed in target.dbg or target.rls, respectively.

After successfull completion of the build process you can copy the target directory to your windows system. Before you can use the cross compiled GTK+ you have to do one additional step on the target platform. So boot your windows box, change to the target directory and type

bin\gdk-pixbuf-query-loaders.exe > etc\gtk-2.0\gdk-pixbuf.loaders

Optionally, if you prefer a more Windows-like look & feel, copy the gtkrc-file of the MS-Windows-theme to your home directory:

copy share\themes\MS-Windows\gtk-2.0\gtkrc %HOME%\.gtkrc-2.0

Now you're ready for take off! Type:


For any comments on the jhbuild script and the moduleset please contact me.

Building the sources from scratch

The easiest thing to do after this is to install the basic dependencies. I've made a tarball of these that you can grab from gtk-deps.tar.gz. You should extract them in /opt (they will extract into ./gtk so your build target is /opt/gtk).


You'll need a mingw-configure script for building each package. Grab it here: mingw-configure

A note about optimizations: the mingw-configure attached does not include any -O optimization flags, so if you want to enable those you should edit the script. However, nasty bugs have been observed in very particular circumstances in gtk# applications when using these optimizations.

Next grab the latest glib, atk, cairo, pango, and gtk+ (either as tarballs or from svn). For each package, you'll need to copy the mingw-configure script into the root directory. Also, if you're pulling the sources out of Subversion instead of using tarballs, you will need to run ./ before running ./mingw-configure for each package, because mingw-configure requires there to be a configure script.

Each time you call mingw-configure, you need to pass it a prefix where you would like to install the Win32 GTK. This should be somewhere that does not conflict with your system files (e.g., do NOT install it to /usr), and it probably should not be where your mingw runtime and compiler are installed. I use /opt/gtk but you can choose anywhere you want. The examples below say --prefix=$YOUR_PREFIX. You may either set an environment variable called YOUR_PREFIX=/opt/gtk or you may specify --prefix=/opt/gtk on each line.

Compiling GLib

When building GLib, you'll need to create a file called win32.cache that looks like this:

  • Copy win32.cache (shown above) into the base directory
  • ./mingw-configure --enable-explicit-deps=no --cache-file=win32.cache --prefix=$YOUR_PREFIX
  • make install

Compiling atk

  • ./mingw-configure --enable-explicit-deps=no --prefix=$YOUR_PREFIX
  • make install

Compiling cairo

  • ./mingw-configure --enable-explicit-deps=no --with-x=no --enable-xlibs=no --enable-xlibs-xrender=no --prefix=$YOUR_PREFIX
  • make install

Compiling pango

  • ./mingw-configure --enable-explicit-deps=no --with-x=no --prefix=$YOUR_PREFIX
  • make install

Compiling GTK+

  • ./mingw-configure --enable-explicit-deps=no --disable-cups --prefix=$YOUR_PREFIX
  • make install


If you have any problems or questions regarding this build process feel free to email me: bratsche at gnome dot org.

Projects/GTK/Win32/CrossCompilingJhbuild (last edited 2018-12-05 15:47:19 by EmmanueleBassi)