~ubuntu-branches/ubuntu/utopic/glib2.0/utopic

« back to all changes in this revision

Viewing changes to docs/reference/glib/html/glib-compiling.html

Tags: upstream-2.12.12
ImportĀ upstreamĀ versionĀ 2.12.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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=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">
 
27
</head>
 
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>
 
35
</tr></table>
 
36
<div class="refentry" lang="en">
 
37
<a name="glib-compiling"></a><div class="titlepage"></div>
 
38
<div class="refnamediv"><table width="100%"><tr>
 
39
<td valign="top">
 
40
<h2><span class="refentrytitle">Compiling GLib Applications</span></h2>
 
41
<p>Compiling GLib Applications &#8212; 
 
42
How to compile your GLib application
 
43
</p>
 
44
</td>
 
45
<td valign="top" align="right"></td>
 
46
</tr></table></div>
 
47
<div class="refsect1" lang="en">
 
48
<a name="id2686368"></a><h2>Compiling GLib Applications on UNIX</h2>
 
49
<p>
 
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.
 
53
</p>
 
54
<p>
 
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):
 
58
</p>
 
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  
 
64
</pre>
 
65
<p>
 
66
</p>
 
67
<p>
 
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: 
 
71
</p>
 
72
<pre class="programlisting">
 
73
$ pkg-config --cflags --libs gthread-2.0
 
74
$ pkg-config --cflags --libs gobject-2.0
 
75
</pre>
 
76
<p>
 
77
</p>
 
78
<p>
 
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: 
 
81
</p>
 
82
<pre class="programlisting">
 
83
$ pkg-config --cflags --libs gmodule-no-export-2.0 
 
84
$ pkg-config --cflags --libs gmodule-2.0 
 
85
</pre>
 
86
<p>
 
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.
 
89
</p>
 
90
<p>
 
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:
 
96
</p>
 
97
<pre class="programlisting">
 
98
$ cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
 
99
</pre>
 
100
<p>
 
101
</p>
 
102
<p>
 
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>.
 
106
</p>
 
107
</div>
 
108
</div>
 
109
</body>
 
110
</html>