## Compiling the GMime libraries

Compiling the GMime Libraries — How to compile GMime itself

## Building GMime on UNIX-like systems

This chapter covers building and installing GMime on UNIX and UNIX-like systems such as Linux. Compiling GMime on Microsoft Windows is not a goal of the project, however if you are able build on a Microsoft Windows platform, do send me building and installing instructions and I will add them to this document.

Before we get into the details of how to compile GMime, I should mention that binary packages of GMime prebuilt for your operating system may be available either from your operating system vendor or from independent sources such as http://rpmfind.net. If you can find them, it may be the easiest way of getting started developing GMime.

On UNIX-like systems GMime 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 GMime from the distributed source packages, then you 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` file which you unpack into a directory full of the source files as follows:

          tar -zxvf gmime-2.4.x.tar.gz

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 specifies where the package is installed. To install a package into `/opt/gmime` you would run configure as:

          ./configure --prefix=/opt/gmime

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
          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`. A quick way to do this is to use the su command with the `-c` option (ex. `su -c "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 a file describing how to compile programs using different libraries. If you were installing GMime and it's dependencies into `/opt/gmime`, you might want to set these variables as:

          CPPFLAGS="-I/opt/gmime/include"
          LDFLAGS="-L/opt/gmime/lib"
          PKG_CONFIG_PATH="/opt/gmime/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.

          LD_LIBRARY_PATH="/opt/gmime/lib"
          PATH="/opt/gmime/bin:$PATH"
          export LD_LIBRARY_PATH PATH

## Dependencies

Before you can compile the GMime 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 GMime 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 GMime 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 GMime is mirrored in the `dependencies` directory on the GTK+ FTP site.

- The GMime makefiles will mostly work with different versions of make, however, there tends to be a few incompatibilities, so the GMime 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.)

GMime depends on the existance of two (2) libraries: GLib and iconv.

- The GLib library provides core non-graphical functionality such as high level data types, Unicode manipulation, and a object and type system to C programs. It is available from the GTK+ FTP site.

- The GNU libiconv library is needed to build GLib and GMime if your system doesn't already have the `iconv()` function for doing conversion between character encodings. Most modern systems should have `iconv()`.

## Building and testing GMime

First make sure that you have the necessary external dependencies installed: pkg-config, GNU make, and, if necessary, libiconv. To get detailed information about building these packages, see the documentation provided with the individual packages. On a newer Linux system, it's quite likely that you'll have all of these installed already.

Then build and install the GMime libraries in the order: libiconv, GLib, then GMime. For each library, follow the steps of `configure`, `make`, `make install` mentioned above. If you're lucky, this will all go smoothly, and you'll be ready to start compiling your own GMime applications. You can test your GMime installation by running pkg-config --modversion gmime-2.4 and making sure that it can both find GMime and reports the correct version.

If one of the `configure` scripts fails or running make fails, look closely at the error messages printed; these will often provide useful information as to what went wrong. When `configure` fails, extra information, such as errors that a test compilation ran into, is found in the file `config.log`. Looking at the last couple of hundred lines in this file will frequently make clear what went wrong. If all else fails, you can ask for help by emailing me, fejj@gnome.org

## Extra Configuration Options

In addition to the normal options, the configure script for the GMime library supports a number of additional arguments. (Command line arguments for the other GMime libraries are described in the documentation distributed with those libraries.)

`./configure` [[--enable-profiling] | [--enable-warnings] | [--enable-mono] | [--enable-gtk-doc] | [--enable-largfile]]

`--enable-profiling` . Normally GMime will not pass the `-pg` flag to gcc when building. This option will enable the use of that flag thus building profiling information into the GMime libraries for use with the GNU Profiler, gprof. Odds are you do not care about this option unless you are either me or desire to profile GMime and/or your program.

`--enable-warnings` . This option enables parser warnings about invalid MIME to be logged to stderr at runtime. Again, it is unlikely you will care to use this option.

`--enable-mono` . This option will include the Mono .NET bindings as part of the build.

`--enable-gtk-doc` . This option will enable the building of the reference documentation for GMime (e.g. the html pages you are reading now).

`--enable-largefile` . This option will enable large file support (e.g. files larger than 2GB) on 32bit systems. This flag is enabled by default starting with GMime 2.4.5.