## Compiling the GLib package Compiling the GLib Package — How to compile GLib itself |

## Building the Library on UNIX

On UNIX, GLib 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. The normal sequence for compiling and installing the GLib library is thus:

`./configure`
`make`
`make install`

The standard options provided by GNU autoconf may be passed to the configure script. Please see the autoconf documentation or run ./configure --help for information about the standard options.

GLib is compiled with strict aliasing disabled. It is strongly recommended that this is not re-enabled by overriding the compiler flags, as GLib has not been tested with strict aliasing and cannot be guaranteed to work.

The GTK+ documentation contains further details about the build process and ways to influence it.

## Dependencies

Before you can compile the GLib library, you need to have various other tools and libraries installed on your system. If you are building from a release archive, you will need a compliant C toolchain, GNU Make, and pkg-config; if you are building directly from a Git repository clone of GLib, you will also need the GNU Autotools mentioned above.

- pkg-config is a tool for tracking the compilation flags needed for libraries that are used by the GLib library. (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 GLib Makefiles make use of several features specific to GNU make, and will not build correctly with other versions of make. You will need to install it if you don't already have it on your system. (It may be called gmake rather than make.)

A UNIX build of GLib requires that the system implements at least the original 1990 version of POSIX. Beyond this, it depends on a number of other libraries.

- 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 have `iconv()`, however many older systems lack an `iconv()` implementation. On such systems, you must install the libiconv library. This can be found at: http://www.gnu.org/software/libiconv.

  If your system has an `iconv()` implementation but you want to use libiconv instead, you can pass the `--with-libiconv` option to configure. This forces libiconv to be used.

  Note that if you have libiconv installed in your default include search path (for instance, in `/usr/local/`), but don't enable it, you will get an error while compiling GLib because the `iconv.h` that libiconv installs hides the system iconv.

  If you are using the native iconv implementation on Solaris instead of libiconv, you'll need to make sure that you have the converters between locale encodings and UTF-8 installed. At a minimum you'll need the SUNWuiu8 package. You probably should also install the SUNWciu8, SUNWhiu8, SUNWjiu8, and SUNWkiu8 packages.

  The native iconv on Compaq Tru64 doesn't contain support for UTF-8, so you'll need to use GNU libiconv instead. (When using GNU libiconv for GLib, you'll need to use GNU libiconv for GNU gettext as well.) This probably applies to related operating systems as well.

- The libintl library from the GNU gettext package is needed if your system doesn't have the `gettext()` functionality for handling message translation databases.

- A thread implementation is needed. The thread support in GLib can be based upon POSIX threads or win32 threads.

- GRegex uses the PCRE library for regular expression matching. The default is to use the system version of PCRE, to reduce the chances of security fixes going out of sync. GLib additionally provides an internal copy of PCRE in case the system version is too old, or does not support UTF-8; the internal copy is patched to use GLib for memory management and to share the same Unicode tables.

- The optional extended attribute support in GIO requires the `getxattr()` family of functions that may be provided by the C library or by the standalone libattr library. To build GLib without extended attribute support, use the `--disable-xattr` option.

- The optional SELinux support in GIO requires libselinux. To build GLib without SELinux support, use the `--disable-selinux` option.

- The optional support for DTrace requires the `sys/sdt.h` header, which is provided by SystemTap on Linux. To build GLib without DTrace, use the `--disable-dtrace` configure option.

- The optional support for SystemTap can be disabled with the `--disable-systemtap` configure option. Additionally, you can control the location where GLib installs the SystemTap probes, using the `--with-tapset-install-dir=DIR` configure option.

## Extra Configuration Options

In addition to the normal options, the configure script in the GLib library supports these additional arguments:

`--enable-debug`. Turns on various amounts of debugging support. Setting this to 'no' disables `g_assert()`, `g_return_if_fail()`, `g_return_val_if_fail()` and all cast checks between different object types. Setting it to 'minimum' disables only cast checks. Setting it to 'yes' enables runtime debugging. The default is 'minimum' for stable releases, and 'yes' for development snapshots. Note that 'no' is fast, but dangerous as it tends to destabilize even mostly bug-free software by changing the effect of many bugs from simple warnings into fatal crashes. Thus `--enable-debug=no` should not be used for stable releases of GLib.

`--with-threads`. Specify a thread implementation to use. Available options are 'posix' or 'win32'. Normally, configure should be able to work out the system threads API on its own.

`--with-pcre`. Specify whether to use the internal or the system-supplied PCRE library.

- 'internal' means that GRegex will be compiled to use the internal PCRE library.

- 'system' means that GRegex will be compiled to use the system-supplied PCRE library; this is the default setting.

Using the internal PCRE is the preferred solution if:

- your system has strict resource constraints; the system-supplied PCRE has a separated copy of the tables used for Unicode handling, whereas the internal copy shares the Unicode tables used by GLib.

- your system has PCRE built without some needed features, such as UTF-8 and Unicode support.

- you are planning to use both GRegex and PCRE API at the same time, either directly or indirectly through a dependency; PCRE uses some global variables for memory management and other features, and if both GLib and PCRE try to access them at the same time, this could lead to undefined behavior.

`--disable-included-printf` and `--enable-included-printf`. By default the configure script will try to auto-detect whether the C library provides a suitable set of `printf()` functions. In detail, configure checks that the semantics of `snprintf()` are as specified by C99 and that positional parameters as specified in the Single Unix Specification are supported. If this not the case, GLib will include an implementation of the `printf()` family. These options can be used to explicitly control whether an implementation of the `printf()` family should be included or not.

`--disable-Bsymbolic` and `--enable-Bsymbolic`. By default, GLib uses the `-Bsymbolic-functions` linker flag to avoid intra-library PLT jumps. A side-effect of this is that it is no longer possible to override internal uses of GLib functions with `LD_PRELOAD`. Therefore, it may make sense to turn this feature off in some situations. The `--disable-Bsymbolic` option allows to do that.

`--disable-gtk-doc` and `--enable-gtk-doc`. By default the configure script will try to auto-detect whether the gtk-doc package is installed. If it is, then it will use it to extract and build the documentation for the GLib library. These options can be used to explicitly control whether gtk-doc should be used or not. If it is not used, the distributed, pre-generated HTML files will be installed instead of building them on your machine.

`--disable-man` and `--enable-man`. By default the configure script will try to auto-detect whether xsltproc and the necessary Docbook stylesheets are installed. If they are, then it will use them to rebuild the included man pages from the XML sources. These options can be used to explicitly control whether man pages should be rebuilt used or not. The distribution includes pre-generated man pages.

`--disable-xattr` and `--enable-xattr`. By default the configure script will try to auto-detect whether the `getxattr()` family of functions is available. If it is, then extended attribute support will be included in GIO. These options can be used to explicitly control whether extended attribute support should be included or not. `getxattr()` and friends can be provided by glibc or by the standalone libattr library.

`--disable-selinux` and `--enable-selinux`. By default the configure script will auto-detect if libselinux is available and include SELinux support in GIO if it is. These options can be used to explicitly control whether SELinux support should be included.

`--disable-dtrace` and `--enable-dtrace`. By default the configure script will detect if DTrace support is available, and use it.

`--disable-systemtap` and `--enable-systemtap`. This option requires DTrace support. If it is available, then the configure script will also check for the presence of SystemTap.

`--enable-coverage` and `--disable-coverage`. Enable the generation of coverage reports for the GLib tests. This requires the lcov frontend to gcov from the Linux Test Project. To generate a coverage report, use the lcov make target. The report is placed in the `glib-lcov` directory.

`--with-runtime-libdir=RELPATH`. Allows specifying a relative path to where to install the runtime libraries (meaning library files used for running, not developing, GLib applications). This can be used in operating system setups where programs using GLib needs to run before e.g. `/usr` is mounted. For example, if `LIBDIR` is `/usr/lib` and `../../lib` is passed to `--with-runtime-libdir` then the runtime libraries are installed into `/lib` rather than `/usr/lib`.

`--with-python=PATH`. Allows specifying the Python interpreter to use, either as an absolute path, or as a program name. GLib can be built with Python 2 (at least version 2.7) or, preferably, with Python 3.