Tizen 2.1 base
[platform/upstream/glib2.0.git] / docs / reference / glib / html / glib-compiling.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Compiling GLib Applications</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib.html" title="GLib Overview">
9 <link rel="prev" href="glib-cross-compiling.html" title="Cross-compiling the GLib package">
10 <link rel="next" href="glib-running.html" title="Running GLib Applications">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
16 <td><a accesskey="p" href="glib-cross-compiling.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
17 <td><a accesskey="u" href="glib.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
18 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
19 <th width="100%" align="center">GLib Reference Manual</th>
20 <td><a accesskey="n" href="glib-running.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
21 </tr></table>
22 <div class="refentry">
23 <a name="glib-compiling"></a><div class="titlepage"></div>
24 <div class="refnamediv"><table width="100%"><tr>
25 <td valign="top">
26 <h2><span class="refentrytitle">Compiling GLib Applications</span></h2>
27 <p>Compiling GLib Applications — 
28 How to compile your GLib application
29 </p>
30 </td>
31 <td valign="top" align="right"></td>
32 </tr></table></div>
33 <div class="refsect1">
34 <a name="id435415"></a><h2>Compiling GLib Applications on UNIX</h2>
35 <p>
36 To compile a GLib application, you need to tell the compiler where to
37 find the GLib header files and libraries. This is done with the
38 <span class="application">pkg-config</span> utility.
39 </p>
40 <p>
41 The following interactive shell session demonstrates how
42 <span class="application">pkg-config</span> is used (the actual output on
43 your system may be different):
44 </p>
45 <pre class="programlisting">
46 $ pkg-config --cflags glib-2.0
47  -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
48 $ pkg-config --libs glib-2.0
49  -L/usr/lib -lm -lglib-2.0
50 </pre>
51 <p>
52 </p>
53 <p>
54 See the <a class="ulink" href="http://www.freedesktop.org/wiki/Software/pkg-config" target="_top">pkg-config website</a>
55 for more information about <span class="application">pkg-config</span>.
56 </p>
57 <p>
58 If your application uses or <span class="structname">GObject</span>
59 features, it must be compiled and linked with the options returned
60 by the following <span class="application">pkg-config</span> invocation:
61 </p>
62 <pre class="programlisting">
63 $ pkg-config --cflags --libs gobject-2.0
64 </pre>
65 <p>
66 </p>
67 <p>
68 If your application uses modules, it must be compiled and linked
69 with the options returned by one of the following
70 <span class="application">pkg-config</span> invocations:
71 </p>
72 <pre class="programlisting">
73 $ pkg-config --cflags --libs gmodule-no-export-2.0
74 $ pkg-config --cflags --libs gmodule-2.0
75 </pre>
76 <p>
77 The difference between the two is that gmodule-2.0 adds
78 <code class="option">--export-dynamic</code> to the linker flags,
79 which is often not needed.
80 </p>
81 <p>
82 The simplest way to compile a program is to use the "backticks"
83 feature of the shell. If you enclose a command in backticks
84 (<span class="emphasis"><em>not single quotes</em></span>), then its output will
85 be substituted into the command line before execution. So to
86 compile a GLib Hello, World, you would type the following:
87 </p>
88 <pre class="programlisting">
89 $ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
90 </pre>
91 <p>
92 </p>
93 <p>
94 Deprecated GLib functions are annotated to make the compiler
95 emit warnings when they are used (e.g. with gcc, you need to use
96 the -Wdeprecated-declarations option). If these warnings are
97 problematic, they can be turned off by defining the preprocessor
98 symbol <code class="literal">GLIB_DISABLE_DEPRECATION_WARNINGS</code> by using the commandline
99 option <code class="literal">-DGLIB_DISABLE_DEPRECATION_WARNINGS</code>
100 </p>
101 <p>
102 GLib deprecation annotations are versioned; by defining the
103 macros <a class="link" href="glib-Version-Information.html#GLIB-VERSION-MIN-REQUIRED:CAPS" title="GLIB_VERSION_MIN_REQUIRED"><code class="literal">GLIB_VERSION_MIN_REQUIRED</code></a> and <a class="link" href="glib-Version-Information.html#GLIB-VERSION-MAX-ALLOWED:CAPS" title="GLIB_VERSION_MAX_ALLOWED"><code class="literal">GLIB_VERSION_MAX_ALLOWED</code></a>,
104 you can specify the range of GLib versions whose API you want
105 to use. APIs that were deprecated before or introduced after
106 this range will trigger compiler warnings.
107 </p>
108 <p>
109 The older deprecation mechanism of hiding deprecated interfaces
110 entirely from the compiler by using the preprocessor symbol
111 G_DISABLE_DEPRECATED is still used for deprecated macros,
112 enumeration values, etc. To detect uses of these in your code,
113 use the commandline option <code class="literal">-DG_DISABLE_DEPRECATED</code>.
114 </p>
115 <p>
116 The recommended way of using GLib has always been to only include the
117 toplevel headers <code class="filename">glib.h</code>,
118 <code class="filename">glib-object.h</code>, <code class="filename">gio.h</code>.
119 Starting with 2.32, GLib enforces this by generating an error
120 when individual headers are directly included.
121 </p>
122 <p>
123 Still, there are some exceptions; these headers have to be included
124 separately:
125 <code class="filename">gmodule.h</code>,
126 <code class="filename">glib-unix.h</code>,
127 <code class="filename">glib/gi18n-lib.h</code> or
128 <code class="filename">glib/gi18n.h</code> (see
129 the <a class="link" href="glib-I18N.html" title="Internationalization">Internationalization section</a>),
130 <code class="filename">glib/gprintf.h</code> and
131 <code class="filename">glib/gstdio.h</code>
132 (we don't want to pull in all of stdio).
133 </p>
134 </div>
135 </div>
136 <div class="footer">
137 <hr>
138           Generated by GTK-Doc V1.18</div>
139 </body>
140 </html>