Compiling the GTK+ Libraries — How to compile GTK+ itself
Building GTK+ on UNIX-like systemsThis chapter covers building and installing GTK+ on UNIX and UNIX-like systems such as Linux. Compiling GTK+ on Microsoft Windows is different in detail and somewhat more difficult to get going since the necessary tools aren't included with the operating system.
Before we get into the details of how to compile GTK+, we should mention that in many cases, binary packages of GTK+ prebuilt for your operating system will be available, either from your operating system vendor or from independent sources. If such a set of packages is available, installing it will get you programming wih GTK+ much faster than building it yourself. In fact, you may well already have GTK+ installed on your system already.
On UNIX-like systems GTK+ uses the standard GNU build system, using autoconf for package configuration and resolving portability issues, automake for building makefiles that comply with the GNU Coding Standards, and libtool for building shared libraries on multiple platforms.
If you are building GTK+ from the distributed source packages, then won't need these tools installed; the necessary pieces of the tools are already included in the source packages. But it's useful to know a bit about how packages that use these tools work. A source package is distributed as a tar.gz
or tar.bz2
file which you unpack into a directory full of the source files as follows:
tar xvfj gtk+-2.0.0.tar.bz2
In the toplevel of the directory that is created, there will be a shell script called configure
which you then run to take the template makefiles called Makefile.in
in the package and create makefiles customized for your operating system. The configure
script can be passed various command line arguments to determine how the package is built and installed. The most commonly useful argument is the --prefix
argument which determines where the package is installed. To install a package in /opt/gtk
you would run configure as:
A full list of options can be found by running configure
with the --help
argument. In general, the defaults are right and should be trusted. After you've run configure
, you then run the make command to build the package and install it.
make install
If you don't have permission to write to the directory you are installing in, you may have to change to root temporarily before running make install
. Also, if you are installing in a system directory, on some systems (such as Linux), you will need to run ldconfig after make install
so that the newly installed libraries will be found.
Several environment variables are useful to pass to set before running configure. CPPFLAGS
contains options to pass to the C compiler, and is used to tell the compiler where to look for include files. The LDFLAGS
variable is used in a similar fashion for the linker. Finally the PKG_CONFIG_PATH
environment variable contains a search path that pkg-config (see below) uses when looking for for file describing how to compile programs using different libraries. If you were installing GTK+ and it's dependencies into /opt/gtk
, you might want to set these variables as:
LDFLAGS="-L/opt/gtk/lib"
PKG_CONFIG_PATH="/opt/gtk/lib/pkgconfig"
export CPPFLAGS LDFLAGS PKG_CONFIG_PATH
You may also need to set the LD_LIBRARY_PATH
environment variable so the systems dynamic linker can find the newly installed libraries, and the PATH
environment program so that utility binaries installed by the various libraries will be found.
PATH="/opt/gtk/bin:$PATH"
export LD_LIBRARY_PATH PATH Dependencies
Before you can compile the GTK+ widget toolkit, you need to have various other tools and libraries installed on your system. The two tools needed during the build process (as differentiated from the tools used in when creating GTK+ mentioned above such as autoconf) are pkg-config and GNU make.
-
pkg-config is a tool for tracking the compilation flags needed for libraries that are used by the GTK+ libraries. (For each library, a small
.pc
text file is installed in a standard location that contains the compilation flags needed for that library along with version number information.) The version of pkg-config needed to build GTK+ is mirrored in thedependencies
directory on the GTK+ FTP site. -
The GTK+ makefiles will mostly work with different versions of make, however, there tends to be a few incompatibilities, so the GTK+ team recommends installing GNU make if you don't already have it on your system and using it. (It may be called gmake rather than make.)
Three of the libraries that GTK+ depends on are maintained by by the GTK+ team: GLib, Pango, and ATK. Other libraries are maintained separately.
-
The GLib library provides core non-graphical functionality such as high level data types, Unicode manipulation, and an object and type system to C programs. It is available from the GTK+ FTP site.
-
Pango is a library for internationalized text handling. It is available from the GTK+ FTP site..
-
ATK is the Accessibility Toolkit. It provides a set of generic interfaces allowing accessibility technologies such as screen readers to interact with a graphical user interface. It is available from the
-
The GNU libiconv library is needed to build GLib if your system doesn't have the
iconv()
function for doing conversion between character encodings. Most modern systems should haveiconv()
. -
The libintl library from the GNU gettext package is needed if your system doesn't have the
gettext()
functionality for handling message translation databases. -
The , PNG, and TIFF image loading libraries are needed to compile GTK+. You probably already have these libraries installed, but if not, the versions you need are available in the
dependencies
directory on the the GTK+ FTP site.. (Before installing these libraries from source, you should check if your operating system vendor has prebuilt packages of these libraries that you don't have installed.) -
The libraries from the X window system are needed to build Pango and GTK+. You should already have these installed on your system, but it's possible that you'll need to install the development environment for these libraries that your operating system vendor provides.
-
The fontconfig library provides Pango with a standard way of locating fonts and matching them against font names.
-
Cairo is a graphics library that supports vector graphics and image compositing. Both Pango and GTK+ use cairo for much of their drawing.
-
The shared-mime-info package is not a hard dependency of GTK+, but it contains definitions for mime types that are used by GIO and, indirectly, by GTK+. gdk-pixbuf will use GIO for mime type detection if possible. For this to work, shared-mime-info needs to be installed and
XDG_DATA_DIRS
set accordingly at configure time. Otherwise, gdk-pixbuf falls back to its built-in mime type detection.