Compiling GLib Applications

Compiling GLib Applications — How to compile your GLib application

Compiling GLib Applications on UNIX

To compile a GLib application, you need to tell the compiler where to find the GLib header files and libraries. This is done with the pkg-config utility.

The following interactive shell session demonstrates how pkg-config is used:

$ pkg-config --cflags glib-2.0
 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include 
$ pkg-config --libs glib-2.0
 -L/usr/lib -lm -lglib-1.3  

If your application uses modules, threads or GObject features, it must be compiled and linked with the options returned by the following pkg-config invokations:

$ pkg-config --cflags --libs gmodule-2.0 
$ pkg-config --cflags --libs gthread-2.0
$ pkg-config --cflags --libs gobject-2.0

The simplest way to compile a program is to use the "backticks" feature of the shell. If you enclose a command in backticks (not single quotes), then its output will be substituted into the command line before execution. So to compile a GLib Hello, World, you would type the following:

$ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello