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.

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. The two tools needed during the build process (as differentiated from the tools used in when creating GLib 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 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 version of pkg-config needed to build GLib is mirrored in the dependencies 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.)

GLib 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, unless you want to compile GLib without thread support, which is not recommended. The thread support in GLib can be based upon several native thread implementations, e.g. POSIX threads, DCE threads or Solaris threads.

Extra Configuration Options

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

configure [[--enable-debug=[no|minimum|yes]]] [[--disable-gc-friendly] | [--enable-gc-friendly]] [[--disable-mem-pools] | [--enable-mem-pools]] [[--disable-threads] | [--enable-threads]] [[--with-threads=[none|posix|dce|win32]]] [[--disable-included-printf] | [--enable-included-printf]] [[--disable-visibility] | [--enable-visibility]] [[--disable-gtk-doc] | [--enable-gtk-doc]] [[--disable-man] | [--enable-man]]

--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'. 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.

--disable-gc-friendly and --enable-gc-friendly By default, and with --disable-gc-friendly as well, Glib does not clear the memory for certain objects before they are freed. For example, Glib may decide to recycle GList nodes by putting them in a free list. However, memory profiling and debugging tools like Valgrind work better if an application does not keep dangling pointers to freed memory (even though these pointers are no longer dereferenced), or invalid pointers inside uninitialized memory. The --enable-gc-friendly option makes Glib clear memory in these situations:

  • When shrinking a GArray, Glib will clear the memory no longer available in the array: shrink an array from 10 bytes to 7, and the last 3 bytes will be cleared. This includes removals of single and multiple elements.

  • When growing a GArray, Glib will clear the new chunk of memory. Grow an array from 7 bytes to 10 bytes, and the last 3 bytes will be cleared.

  • The above applies to GPtrArray as well.

  • When freeing a node from a GHashTable, Glib will first clear the node, which used to have pointers to the key and the value stored at that node.

  • When destroying or removing a GTree node, Glib will clear the node, which used to have pointers to the node's value, and the left and right subnodes.

Since clearing the memory has a cost, --disable-gc-friendly is the default.

--disable-mem-pools and --enable-mem-pools Many small chunks of memory are often allocated via collective pools in GLib and are cached after release to speed up reallocations. For sparse memory systems this behaviour is often inferior, so memory pools can be disabled to avoid excessive caching and force atomic maintenance of chunks through the g_malloc() and g_free() functions. Code currently affected by this:

  • GList, GSList, GNode, GHash allocations. The functions g_list_push_allocator(), g_list_pop_allocator(), g_slist_push_allocator(), g_slist_pop_allocator(), g_node_push_allocator() and g_node_pop_allocator() are not available

  • GMemChunks become basically non-effective

  • GSignal disables all caching (potentially very slow)

  • GType doesn't honour the GTypeInfo n_preallocs field anymore

  • the GBSearchArray flag G_BSEARCH_ALIGN_POWER2 becomes non-functional

--disable-threads and --enable-threads Do not compile GLib to be multi thread safe. GLib will be slightly faster then. This is however not recommended, as many programs rely on GLib being multi thread safe.

--with-threads Specify a thread implementation to use.

  • 'posix' and 'dce' can be used interchangeable to mean the different versions of Posix threads. configure tries to find out, which one is installed.

  • 'none' means that GLib will be thread safe, but does not have a default thread implementation. This has to be supplied to g_thread_init() by the programmer.

--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 fo the printf() family should be included or not.

--disable-visibility and --enable-visibility By default, GLib uses ELF visibility attributes to optimize PLT table entries if the compiler supports ELF visibility attributes. A side-effect of the way in which this is currently implemented is that any header change forces a full recompilation, and missing includes may go unnoticed. Therefore, it makes sense to turn this feature off while doing GLib development, even if the compiler supports ELF visibility attributes. The --disable-visibility 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.