Cross-compiling Win32 GTK 2.10.2 on Linux

Cody Russell

Back home...

Binaries: You can grab my pre-built binaries here in 2.10.tar.gz. Just unzip it to c:\gtk and it should create the c:\gtk\2.10 subdirectory. Next you need to set your system PATH environment to include c:\gtk\2.10\bin and you should be good to go.

Compiling GTK sources..

Notes: I am doing all of this under Ubuntu Dapper 6.06, although I am using GTK 2.10.2 and its related dependencies on my system (e.g., GLib 2.12.x, Pango 1.14.x, etc). This difference in GTK versions will affect you at the point where you build GTK itself, but you don't need to have GTK 2.10 installed on your system. If you're using the pre-built dependencies (link under item #1 below), then your build target is /opt/gtk. The mingw-configure script will automatically set the prefix to that directory, so you don't need to add --prefix

If you want to build all the dependencies from source, good luck. It's a pain in the ass and it's not worth the effort. I've provided binaries of those dependencies so you can spend your time building things that you may actually want to hack on: GLib, Cairo, ATK, Pango, and GTK. But if you're someone who distrusts binaries made by other people then feel free to build your own. You may also find Tor Lillqvist's Evolution on Windows docs informative.

Tor has been building GTK related stuff on Windows for awhile, and he helped me a lot in getting this stuff working this weekend, so a big thanks to him and to the others on #gtk+ who helped. Tor has been building GTK on Windows itself, while this document describes how to cross-compile from Linux.

  1. Install mingw. I'm using whatever version is available through apt for Ubuntu Dapper.
  2. Extract gtk-deps.tar.gz in /opt
  3. Untar glib tarball (I used 2.12.2). Copy mingw-configure and win32.cache into the base directory.
  4. ./mingw-configure --enable-explicit-deps=no --cache-file=win32.cache ; make install
  5. Untar atk and do ./mingw-configure --enable-explicit-deps=no ; make install
  6. Extract cairo tarball (I used 1.2.4). Copy mingw-configure into the base directory.
  7. ./mingw-configure --enable-explicit-deps=no --with-x=no ; make install
  8. Extract pango (I used 1.14.2), copy mingw-configure into the base.
  9. ./mingw-configure --enable-explicit-deps=no --with-x=no ; make install
  10. Extract gtk tarball and copy mingw-configure into its directory.
  11. If you're using 2.10, you need to edit gtk/Makefile.am and turn all references to gtk-update-icon-cache to gtk-update-icon-cache$(EXEEXT) and on line 833 you need to change gtk-query-immodules-2.0 to gtk-immodules-2.0$(EXEEXT) - or just grab Makefile.am and drop it into gtk+-2.10.2/gtk/ and replace the Makefile.am that is there already.
  12. You need a gtk-update-icon-cache binary that is built for your system (not Win32), and it needs to be from GTK 2.10.x. If you have 2.10.x installed, copy your {prefix}/bin/gtk-update-icon-cache into gtk. Otherwise, if you're on 32-bit Intel cpu then you can use mine. This is needed to generate the gtkbuiltincache.h file at compile-time. After that is generated, a gtk-update-icon-cache.exe should be created and libtool will replace the current gtk-update-icon-cache binary with a script file that calls the .exe file. If you're not using 32-bit Intel cpu you're going to need to build GTK 2.10 for your architecture.
  13. Update: Apparently it's not generating gtkbuiltincache.h correctly so until that is solved just grab this one. Otherwise your stock icons will not show up correctly.
  14. ./mingw-configure --enable-explicit-deps=no ; make install
After all of that is done everything should be installed to /opt/gtk and you can tar or zip it up and transfer it over to your Windows system.

Create c:\gtk if it doesn't already exist and then unzip/untar your build into that directory (it should unzip into c:\gtk\gtk). Rename c:\gtk\gtk to c:\gtk\2.10

Next create the c:\gtk\2.10\etc\gtk-2.0 directory. Grab gdk-pixbuf.loaders and gtk.immodules and put them in that directory.

Next create the c:\gtk\2.10\etc\pango directory. Grab pango.aliases and pango.modules and put them in that directory.

Grab gtkrc and put it in c:\gtk\2.10\etc\gtk-2.0

If you haven't done so yet, set your system PATH environment to include c:\gtk\2.10\bin

Go into c:\gtk\2.10\bin and execute gtk-demo.exe - if all went well, it should run as expected and fonts should be visible. Go to the image test and make sure that your pixbufs are loading correctly.

If you encounter any problems, or have any other things you want to contribute to this then please contact me. I am usually on GimpNet irc under the name bratsche, although I may be afk. Feel free to email me at bratsche at gnome dot org.

-- Cody