GTK+ is a set of open-source widget libraries that are mature, functional and portable. GTK+ library is mainly used by many Linux programs. I am building a complete stack of GTK+ 2.x library before beginning my programming projects. This tutorial makes use of the free MinGW compiler to build GTK+.
This post focuses on compiling 32-bit binaries. If you intend to develop 64-bit GTK+ applications, read this post on building 64-bit GTK+. Although distantly related, you can also build a GTK+ library with Cygwin gcc4-core that relies on the POSIX emulation layer but doesn't need X Windows.
If you haven't installed MinGW yet, read this tutorial on installing MinGW in Windows. Alternatively, you can also install MinGW Portable on your USB flash drive so you can enjoy compiling anywhere. GTK+ depends on many basic libraries that provide image, localization, font and other functions. These prerequisite libraries have be compiled first. Once you've installed MinGW and MSYS, launch MSYS. The following steps require you to type commands into MSYS console.
Zlib 1.2.7
Zlib is an essential compression library required by png, tiff and cairo. Get the zlib source and unpack it:
tar xzvf zlib-1.2.7.tar.gz cd zlib-1.2.7/
Compile zlib like this:
make -f win32/Makefile.gcc
Then, manually copy the files as follows:
cp -iv zlib1.dll /mingw/bin cp -iv zconf.h zlib.h /mingw/include cp -iv libz.a /mingw/lib cp -iv libz.dll.a /mingw/lib
gettext 0.18.1.1
GNU gettext is a tool for localizing and translating programs. The recent versions of gettext include libiconv, a character-set conversion library, so you don't have to compile libiconv separately. Build gettext like this:
./configure --prefix=/mingw --enable-threads=win32 --enable-relocatable cd gettext-runtime/ make make install
glib 2.32.4
glib's
configurescript requires pkg-config.exe and msgfmt.exe in the PATH. Download the executables and save them in /mingw/bin. Remember to set the system-wide environment variable PKG_CONFIG_PATH:export PKG_CONFIG_PATH=/mingw/lib/pkgconfig
glib 2.30 and later depends on libffi. Compile libffi like this:
./configure --prefix=/mingw && make && make install
Then, get the glib source from ftp.gnome.org and compile glib as follows:
./configure --prefix=/mingw --with-threads=win32 --with-pcre=internal --disable-debug make make install
ATK 2.4.0
Download ATK from here. Compile it like this:
./configure --prefix=/mingw make make install
libpng 1.5.12
PNG can be compiled like this:
./configure --prefix=/mingw make make install
Optional libraries
The following libraries are optional, but many GTK+ packages include them. It's up to you to decide whether to compile them or not.
As usual, compile any of them like this:
./configure --prefix=/mingw && make && make install
Pixman 0.26.2 and Cairo 1.12.2
Get Pixman and Cairo from cairographics.org. Compile Pixman as follows:
./configure --prefix=/mingw
make
make installThen, compile cairo:
./configure --prefix=/mingw --enable-pthread make make install
Pango Library 1.30.1
Compile Pango like this:
./configure --prefix=/mingw --with-included-modules=yes
make
make installgdk-pixbuf 2.26.2
Download and compile gdk-pixbuf:
./configure --prefix=/mingw --without-libjasper --with-included-loaders=yes --disable-modules --disable-debug make make install
GTK+ 2.24.11 and GTK+ 3.4.2
At last, we are ready to compile GTK+ for Windows. I compiled GTK+ like this:
./configure --prefix=/mingw --with-included-immodules=ime --disable-modules --disable-debug
make
make installTo test your newly compiled GTK+ library, run
gtk-demo.exeortestgtk.exe.

