Initial commit
[platform/upstream/glib2.0.git] / docs / reference / glib / compiling.sgml
1 <?xml version="1.0"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3                "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
4 ]>
5 <refentry id="glib-compiling" revision="17 Jan 2002">
6 <refmeta>
7 <refentrytitle>Compiling GLib Applications</refentrytitle>
8 <manvolnum>3</manvolnum>
9 <refmiscinfo>GLib Library</refmiscinfo>
10 </refmeta>
11
12 <refnamediv>
13 <refname>Compiling GLib Applications</refname>
14 <refpurpose>
15 How to compile your GLib application
16 </refpurpose>
17 </refnamediv>
18
19 <refsect1>
20 <title>Compiling GLib Applications on UNIX</title>
21
22 <para>
23 To compile a GLib application, you need to tell the compiler where to 
24 find the GLib header files and libraries. This is done with the
25 <application>pkg-config</application> utility.
26 </para>
27 <para>
28 The following interactive shell session demonstrates how
29 <application>pkg-config</application> is used (the actual output on
30 your system may be different):
31 <programlisting>
32 $ pkg-config --cflags glib-2.0
33  -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include 
34 $ pkg-config --libs glib-2.0
35  -L/usr/lib -lm -lglib-2.0  
36 </programlisting>
37 </para>
38 <para>
39 If your application uses threads or <structname>GObject</structname>
40 features, it must be compiled and linked with the options returned by the 
41 following <application>pkg-config</application> invocations: 
42 <programlisting>
43 $ pkg-config --cflags --libs gthread-2.0
44 $ pkg-config --cflags --libs gobject-2.0
45 </programlisting>
46 </para>
47 <para>
48 If your application uses modules, it must be compiled and linked with the options 
49 returned by one of the following <application>pkg-config</application> invocations: 
50 <programlisting>
51 $ pkg-config --cflags --libs gmodule-no-export-2.0 
52 $ pkg-config --cflags --libs gmodule-2.0 
53 </programlisting>
54 The difference between the two is that gmodule-2.0 adds <option>--export-dynamic</option> 
55 to the linker flags, which is often not needed.
56 </para>
57 <para>
58 The simplest way to compile a program is to use the "backticks"
59 feature of the shell. If you enclose a command in backticks
60 (<emphasis>not single quotes</emphasis>), then its output will be
61 substituted into the command line before execution. So to compile 
62 a GLib Hello, World, you would type the following:
63 <programlisting>
64 $ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
65 </programlisting>
66 </para>
67
68 <para>
69 If you want to make sure that your program doesn't use any deprecated
70 functions, you can define the preprocessor symbol G_DISABLE_DEPRECATED
71 by using the command line option <literal>-DG_DISABLE_DEPRECATED=1</literal>.
72 </para>
73
74 <para>
75 The recommended way of using GLib has always been to only include the 
76 toplevel headers <filename>glib.h</filename>, 
77 <filename>glib-object.h</filename>, <filename>gio.h</filename>.
78 Still, there are some exceptions; these headers have to be included separately:
79 <filename>gmodule.h</filename>,
80 <filename>glib/gi18n-lib.h</filename> or <filename>glib/gi18n.h</filename> (see
81 the <link linkend="glib-I18N">Internationalization section</link>),
82 <filename>glib/gprintf.h</filename> and <filename>glib/gstdio.h</filename>
83 (we don't want to pull in all of stdio).
84 </para>
85
86 <para>
87 Starting with 2.17, GLib enforces this by generating an error
88 when individual headers are directly included. To help with the 
89 transition, the enforcement is not turned on by default for GLib 
90 headers (it <emphasis>is</emphasis> turned on for GObject and GIO).
91 To turn it on, define the preprocessor symbol G_DISABLE_SINGLE_INCLUDES
92 by using the command line option <literal>-DG_DISABLE_SINGLE_INCLUDES</literal>.
93 </para>
94
95 </refsect1>
96
97 </refentry>