1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5
<title>Compiling GLib Applications</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
7
<link rel="start" 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.7 (XML mode)">
12
<link rel="stylesheet" href="style.css" type="text/css">
13
<link rel="chapter" href="glib.html" title="GLib Overview">
14
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18
<link rel="chapter" href="tools.html" title="GLib Tools">
19
<link rel="index" href="ix01.html" title="Index">
20
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
21
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
22
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
23
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
24
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
25
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
28
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
29
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
30
<td><a accesskey="p" href="glib-cross-compiling.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
31
<td><a accesskey="u" href="glib.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
32
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
33
<th width="100%" align="center">GLib Reference Manual</th>
34
<td><a accesskey="n" href="glib-running.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
36
<div class="refentry" lang="en">
37
<a name="glib-compiling"></a><div class="titlepage"></div>
38
<div class="refnamediv"><table width="100%"><tr>
40
<h2><span class="refentrytitle">Compiling GLib Applications</span></h2>
41
<p>Compiling GLib Applications —
42
How to compile your GLib application
45
<td valign="top" align="right"></td>
47
<div class="refsect1" lang="en">
48
<a name="id2686368"></a><h2>Compiling GLib Applications on UNIX</h2>
50
To compile a GLib application, you need to tell the compiler where to
51
find the GLib header files and libraries. This is done with the
52
<span class="application">pkg-config</span> utility.
55
The following interactive shell session demonstrates how
56
<span class="application">pkg-config</span> is used (the actual output on
57
your system may be different):
59
<pre class="programlisting">
60
$ pkg-config --cflags glib-2.0
61
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
62
$ pkg-config --libs glib-2.0
63
-L/usr/lib -lm -lglib-2.0
68
If your application uses threads or <span class="structname">GObject</span>
69
features, it must be compiled and linked with the options returned by the
70
following <span class="application">pkg-config</span> invocations:
72
<pre class="programlisting">
73
$ pkg-config --cflags --libs gthread-2.0
74
$ pkg-config --cflags --libs gobject-2.0
79
If your application uses modules, it must be compiled and linked with the options
80
returned by one of the following <span class="application">pkg-config</span> invocations:
82
<pre class="programlisting">
83
$ pkg-config --cflags --libs gmodule-no-export-2.0
84
$ pkg-config --cflags --libs gmodule-2.0
87
The difference between the two is that gmodule-2.0 adds <code class="option">--export-dynamic</code>
88
to the linker flags, which is often not needed.
91
The simplest way to compile a program is to use the "backticks"
92
feature of the shell. If you enclose a command in backticks
93
(<span class="emphasis"><em>not single quotes</em></span>), then its output will be
94
substituted into the command line before execution. So to compile
95
a GLib Hello, World, you would type the following:
97
<pre class="programlisting">
98
$ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
103
If you want to make sure that your program doesn't use any deprecated
104
functions, you can define the preprocessor symbol G_DISABLE_DEPRECATED
105
by using the command line option <code class="literal">-DG_DISABLE_DEPRECATED=1</code>.