There’s a lot of blog articles about building GTK+ and related libraries for Windows with MinGW. Building them on Windows is not a straight forward task. Most write about the trick and workaround, but those workaround is case by case and requires a lot of searching on the web. So I’ve decided to write one for me.
Precompiled GTK+ for Windows
The GTK+ projects provides the precompiled packages for Windows. GTK+ version is 2.24.10 as of Sep 23, 2012. According to this page, GIMP 2.8.2 requires GLib 2.30.2, however, the precompiled GLib is 2.28.8.
Preparing environments
We are building GTK+ on /opt/gimp. Let’s prepare some environment variables first. I wrote a small shell script env.sh to do this. Type . env.sh
before building.
export GIMP_ROOT=/opt/gimp
if [ -z "$PATH_OLD" ] ; then
PATH_OLD=$PATH
fi
if [ -z "$PS1_OLD" ] ; then
PS1_OLD=$PS1
fi
export PATH=/opt/gimp/bin:/c/Python27:$PATH_OLD
export LANG=C
export PKG_CONFIG_PATH=$GIMP_ROOT/lib/pkgconfig
export CPPFLAGS="-I$GIMP_ROOT/include"
export CFLAGS="-O2 -g -march=i586 -mms-bitfields -I$GIMP_ROOT/include"
export CXXFLAGS="-O2 -g -march=i586 -mms-bitfields -I$GIMP_ROOT/include"
export LIBS="-L$GIMP_ROOT/lib"
export PS1="gimp$ "
What to build first?
There’s a lot of dependency among the packages. What to build first? Many configure scripts of libraries use pkg-config. However, building pkg-config requires Glib to build. (–with-internal-glib probably works but I didn’t notice when building this.) Zlib is required by GIO of Glib and libffi is required by GObject of Glib. These two do not depend on other packages. So we should start with them.
Zlib 1.2.7
Zlib (http://zlib.net/zlib-1.2.7.tar.gz) doesn’t use pkg-config. It has makefiles for Windows. You need to use SHARED_MODE=1 to install the shared library zlib1.dll.
make -fwin32/Makefile.gcc -j4
INCLUDE_PATH=$GIMP_ROOT/include \
LIBRARY_PATH=$GIMP_ROOT/lib \
BINARY_PATH=$GIMP_ROOT/bin \
make install -fwin32/Makefile.gcc SHARED_MODE=1
libffi 3.0.11
libffi (ftp://sourceware.org/pub/libffi/libffi-3.0.11.tar.gz) is a portable foreign function interface library. It is used by GObject to implement marshalling. Building libffi is straight forward.
./configure --prefix=$GIMP_ROOT
make -j4
make install
GLib 2.33.14
The configure script of GLib uses pkgconfig to locate Zlib and libffi. We need to specify manually to avoid it. See Re: circular dependency between glib and pkg-config
There’s a build break in GLib 2.3.14. Apply the patch [glib] gio: Fix build on Windows.
ZLIB_CFLAGS=-I$GIMP_ROOT/include \
ZLIB_LIBS="-L$GIMP_ROOT/lib -lz" \
LIBFFI_CFLAGS=-I$GIMP_ROOT/lib/libffi-3.0.11/include \
LIBFFI_LIBS="-L$GIMP_ROOT/lib -lffi" \
./configure --prefix=$GIMP_ROOT
make -j4
make install
pkg-config 0.27
Pkg-config now can be built.
./configure --prefix=$GIMP_ROOT
make -j4
make install
ATK 2.5.91
Building ATK 2.5.91 is straight forward.
./configure --prefix=$GIMP_ROOT
make -j4
make install
libpng 1.5.12
GDK-Pixbuf uses libpng (http://downloads.sourceforge.net/project/libpng/libpng15/1.5.12/libpng-1.5.12.tar.xz).
./configure --prefix=$GIMP_ROOT
make -j4
make install
GDK-Pixbuf 2.26.4
http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/2.26/gdk-pixbuf-2.26.4.tar.xz
./configure --prefix=$GIMP_ROOT
make -j4
make install
FreeType 2.4.10
Cairo uses FreeType for one of font supports (http://download.savannah.gnu.org/releases/freetype/freetype-2.4.10.tar.gz).
./configure --prefix=$GIMP_ROOT
make -j4
make install
expat 2.1.0
Fontconfig uses expat to parse its configuration files (http://downloads.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz).
./configure --prefix=$GIMP_ROOT
make -j4
make install
Fontconfig 2.10.1
Cairo and Pango use fontconfig (http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.10.1.tar.bz2).
./configure --prefix=$GIMP_ROOT
make -j4
make install
Pixman 0.26.2
Cairo uses Pixman. Pixman (http://cairographics.org/releases/pixman-0.26.2.tar.gz) is distributed with cairo.
./configure --prefix=$GIMP_ROOT
make -j4
make install
Cairo 1.12.2
Pango uses Cairo (http://cairographics.org/releases/cairo-1.12.2.tar.xz).
There’s a build break in util/cairo-missing/cairo-missing.h (https://github.com/libgit2/libgit2/issues/542).
I added this around line 44.
#define _SSIZE_T_DEFINED
Rest of the process is straight forward.
./configure --prefix=$GIMP_ROOT
make -j4
make install
HarfBuzz 0.9.4
HarfBuzz (http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.4.tar.bz2) is a OpenType shaping library. Recent Pango requires HarfBuzz to enable the Cairo rendering support.
./configure --prefix=$GIMP_ROOT
make -j4
make install
Pango 1.31.2
GIMP requires Pango’s Cairo rendering support (http://ftp.gnome.org/pub/gnome/sources/pango/1.31/pango-1.31.2.tar.xz). Make sure that FT2, Win32 and Cairo is supported after configured.
./configure --prefix=$GIMP_ROOT
make -j4
make install
GTK+ 2.24.12
Finally GTK+ (http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/gtk+-2.24.12.tar.xz). All requisits are ready now.
./configure --prefix=$GIMP_ROOT
make -j4
Building fails while generating gtkbuiltincache.h. Type with admin rights (MinGW/MSYS development environment
Part 3: Building GTK+).
cd gtk
make gtkbuiltincache.h
Then continue
make -j4
make install
Run Demo
GTK+ includes demo program. Type
gtk-demo
to see if every thing is okay.