• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<refentry id="glib-compiling" revision="17 Jan 2002">
2<refmeta>
3<refentrytitle>Compiling GLib Applications</refentrytitle>
4<manvolnum>3</manvolnum>
5<refmiscinfo>GLib Library</refmiscinfo>
6</refmeta>
7
8<refnamediv>
9<refname>Compiling GLib Applications</refname>
10<refpurpose>
11How to compile your GLib application
12</refpurpose>
13</refnamediv>
14
15<refsect1>
16<title>Compiling GLib Applications on UNIX</title>
17
18<para>
19To compile a GLib application, you need to tell the compiler where to
20find the GLib header files and libraries. This is done with the
21<application>pkg-config</application> utility.
22</para>
23<para>
24The following interactive shell session demonstrates how
25<application>pkg-config</application> is used (the actual output on
26your system may be different):
27<programlisting>
28$ pkg-config --cflags glib-2.0
29 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
30$ pkg-config --libs glib-2.0
31 -L/usr/lib -lm -lglib-2.0
32</programlisting>
33</para>
34<para>
35If your application uses threads or <structname>GObject</structname>
36features, it must be compiled and linked with the options returned by the
37following <application>pkg-config</application> invocations:
38<programlisting>
39$ pkg-config --cflags --libs gthread-2.0
40$ pkg-config --cflags --libs gobject-2.0
41</programlisting>
42</para>
43<para>
44If your application uses modules, it must be compiled and linked with the options
45returned by one of the following <application>pkg-config</application> invocations:
46<programlisting>
47$ pkg-config --cflags --libs gmodule-no-export-2.0
48$ pkg-config --cflags --libs gmodule-2.0
49</programlisting>
50The difference between the two is that gmodule-2.0 adds <option>--export-dynamic</option>
51to the linker flags, which is often not needed.
52</para>
53<para>
54The simplest way to compile a program is to use the "backticks"
55feature of the shell. If you enclose a command in backticks
56(<emphasis>not single quotes</emphasis>), then its output will be
57substituted into the command line before execution. So to compile
58a GLib Hello, World, you would type the following:
59<programlisting>
60$ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
61</programlisting>
62</para>
63
64<para>
65If you want to make sure that your program doesn't use any deprecated
66functions, you can define the preprocessor symbol G_DISABLE_DEPRECATED
67by using the command line option <literal>-DG_DISABLE_DEPRECATED=1</literal>.
68</para>
69
70<para>
71The recommended way of using GLib has always been to only include the
72toplevel headers <filename>glib.h</filename>,
73<filename>glib-object.h</filename>, <filename>gio.h</filename>.
74Starting with 2.17, GLib enforces this by generating an error
75when individual headers are directly included. To help with the
76transition, the enforcement is not turned on by default for GLib
77headers (it <emphasis>is</emphasis> turned on for GObject and GIO).
78To turn it on, define the preprocessor symbol G_DISABLE_SINGLE_INCLUDES
79by using the command line option <literal>-DG_DISABLE_SINGLE_INCLUDES</literal>.
80</para>
81
82</refsect1>
83
84</refentry>
85