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+.
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/liblibiconv 1.14
libiconv is a character-set conversion library, and is needed by gettext. Download the libiconv source and compile libiconv:
./configure --prefix=/mingw
make
make installgettext 0.18.1.1
GNU gettext is a tool for localizing and translating programs. Build gettext like this:
./configure --prefix=/mingw --enable-threads=win32 --enable-relocatable
cd gettext-runtime/
make
make installglib 2.32.4
glib's
configure
script 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 installATK 2.4.0
Download ATK from here. Compile it like this:
./configure --prefix=/mingw
make
make installlibpng 1.5.12
PNG can be compiled like this:
./configure --prefix=/mingw
make
make installOptional 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 installPango 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 installGTK+ 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.exe
ortestgtk.exe
.
I Can't Build glib .
ReplyDeleteThanks Great Blog !
I build glib latest source from gnome , configure successful but build get error ( I forgot it ) , maybe specified "libiconv" lib dir when config .
ReplyDeleteThanks !
Can you write article about "Mozilla Build" ?
Sorry bad english !
Thanks a lot for great post!
ReplyDeleteWith my mingw install(I used the latest installer), i needed to reinstall crt2.o(under MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/mingwrt-3.18) in order to compile expat and fontconfig.
Those 2 gave errors when compiling:
crt2.o:crt1.c:(.text+0x28): undefined reference to `__dyn_tls_init_callback'
Excelent blog! Congrats.
ReplyDeleteBut i have a problem compiling glib and i can't find anything tosolve it.
The problem appears when i'm doing make.
c:\MinGW\glib-2.24.2\glib\tests/testing.c:232: undefined reference `_imp__g_test_config_vars'
I hope you can help me. If you want more details of the error e-mail me to mpinchei@ampersoft.cl
Thanks in advance
You forgot for gettext step this
ReplyDelete# The name that we can dlopen(3).
dlname='../bin/intl.dll'
# Names of this library.
library_names='libintl.a'
Big thanks for the guide.
I'm not a linux fan (and even less now !), so it took me some hours to find the reason why Pango didn't wanted to build !
ReplyDeleteMake did stopped at the very begining (when showing " GEN s-enum-types-h" in the console) because of an error in the glib-mkenums script. To make it work, i had to modify the very firt line of this file from
#!/usr/bin/env perl -w
to
#!perl -w
I can compile gtk.
ReplyDeleteBut I can not run gtk-demo.
The picture is Successfully Compiled GTK. Have you any idea?
Your tutorial is great !
ReplyDeleteNevertheless, I have a question about the makefiles of glib.
As a matter of fact, the actual makefiles generate one .dll and one .dll.a file for each glib "module" gobjects, ghtreads, gmodules and gio.
Well, I'd like to have only one big .a static file for each module instead (that is libgobjects-2.0.a, libgthreads-2.0.a and so on). No shared library, all static. (old school :)
Do you have an idea if there is an option or how could I change makefile.am ??
Cheers,
Carl
Well I can build all the libraries up to the point where I try to build the atk and it just won't do it no matter what changes I do to get the Glib to work with it, it won't build correctly. It always has a problem with a adk marshalling problem, it states that it can't find the gobject atkmarshal but when I go into the folder, it is there. Your tutorial is great, too bad I can't get seem
ReplyDeleteto get pass the configuration of the atk. It always has "Invalid Parameters" for some of the steps like when it tries to get the Glib, it thinks it is not there so it uses the PKG_CONFIG_PATH environment variable and then it gets to configure but then I can't complete the make and make install steps of the build. It gives me a weird "C:/MinGW/msys/1.0/home/rabbit/glib-2.24.2/gobject/glib-genmarshal : no such file or directory, but it is there and also has the PKG_CONFIG_PATH pointing to it.
In need to build a newer version of GTK+, so I am trying to following your build scheme with newer versions of the various packages. OK with zlib 1.2.6, libiconv 1.14.1 and gettext 0.18.1.1. However, I ran into a problem with glib 2.25.17. I got the following configuration error:
ReplyDelete...
checking for libintl.h... yes
checking for ngettext in libc... no
checking for bindtextdomain in -lintl... no
checking if -liconv is needed to use gettext...
checking for ngettext in -lintl... no
configure: error:
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html
I got this error even though gettext seemed to build and install properly.
Any ideas???