Blame docs/reference/glib/html/glib-compiling.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>Compiling GLib Applications: GLib Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GLib Reference Manual">
Packit ae235b
<link rel="up" href="glib.html" title="GLib Overview">
Packit ae235b
<link rel="prev" href="glib-programming.html" title="Writing GLib Applications">
Packit ae235b
<link rel="next" href="glib-running.html" title="Running GLib Applications">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Compiling GLib Applications

Packit ae235b

Compiling GLib Applications —

Packit ae235b
How to compile your GLib application
Packit ae235b

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Compiling GLib Applications on UNIX

Packit ae235b

Packit ae235b
To compile a GLib application, you need to tell the compiler where to
Packit ae235b
find the GLib header files and libraries. This is done with the
Packit ae235b
pkg-config utility.
Packit ae235b

Packit ae235b

Packit ae235b
The following interactive shell session demonstrates how
Packit ae235b
pkg-config is used (the actual output on
Packit ae235b
your system may be different):
Packit ae235b

Packit ae235b
Packit ae235b
$ pkg-config --cflags glib-2.0
Packit ae235b
 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
Packit ae235b
$ pkg-config --libs glib-2.0
Packit ae235b
 -L/usr/lib -lm -lglib-2.0
Packit ae235b
Packit ae235b

Packit ae235b

Packit ae235b

Packit ae235b
See the pkg-config website
Packit ae235b
for more information about pkg-config.
Packit ae235b

Packit ae235b

Packit ae235b
If your application uses or GObject
Packit ae235b
features, it must be compiled and linked with the options returned
Packit ae235b
by the following pkg-config invocation:
Packit ae235b

Packit ae235b
Packit ae235b
$ pkg-config --cflags --libs gobject-2.0
Packit ae235b
Packit ae235b

Packit ae235b

Packit ae235b

Packit ae235b
If your application uses modules, it must be compiled and linked
Packit ae235b
with the options returned by one of the following
Packit ae235b
pkg-config invocations:
Packit ae235b

Packit ae235b
Packit ae235b
$ pkg-config --cflags --libs gmodule-no-export-2.0
Packit ae235b
$ pkg-config --cflags --libs gmodule-2.0
Packit ae235b
Packit ae235b

Packit ae235b
The difference between the two is that gmodule-2.0 adds
Packit ae235b
--export-dynamic to the linker flags,
Packit ae235b
which is often not needed.
Packit ae235b

Packit ae235b

Packit ae235b
The simplest way to compile a program is to use the "backticks"
Packit ae235b
feature of the shell. If you enclose a command in backticks
Packit ae235b
(not single quotes), then its output will
Packit ae235b
be substituted into the command line before execution. So to
Packit ae235b
compile a GLib Hello, World, you would type the following:
Packit ae235b

Packit ae235b
Packit ae235b
$ cc hello.c `pkg-config --cflags --libs glib-2.0` -o hello
Packit ae235b
Packit ae235b

Packit ae235b

Packit ae235b

Packit ae235b
Note that the name of the file must come before the other options
Packit ae235b
(such as pkg-config), or else you may get an
Packit ae235b
error from the linker.
Packit ae235b

Packit ae235b

Packit ae235b
Deprecated GLib functions are annotated to make the compiler
Packit ae235b
emit warnings when they are used (e.g. with gcc, you need to use
Packit ae235b
the -Wdeprecated-declarations option). If these warnings are
Packit ae235b
problematic, they can be turned off by defining the preprocessor
Packit ae235b
symbol GLIB_DISABLE_DEPRECATION_WARNINGS by using the commandline
Packit ae235b
option -DGLIB_DISABLE_DEPRECATION_WARNINGS
Packit ae235b

Packit ae235b

Packit ae235b
GLib deprecation annotations are versioned; by defining the
Packit ae235b
macros GLIB_VERSION_MIN_REQUIRED and GLIB_VERSION_MAX_ALLOWED,
Packit ae235b
you can specify the range of GLib versions whose API you want
Packit ae235b
to use. APIs that were deprecated before or introduced after
Packit ae235b
this range will trigger compiler warnings.
Packit ae235b

Packit ae235b

Packit ae235b
The older deprecation mechanism of hiding deprecated interfaces
Packit ae235b
entirely from the compiler by using the preprocessor symbol
Packit ae235b
G_DISABLE_DEPRECATED is still used for deprecated macros,
Packit ae235b
enumeration values, etc. To detect uses of these in your code,
Packit ae235b
use the commandline option -DG_DISABLE_DEPRECATED.
Packit ae235b

Packit ae235b

Packit ae235b
The recommended way of using GLib has always been to only include the
Packit ae235b
toplevel headers glib.h,
Packit ae235b
glib-object.h, gio.h.
Packit ae235b
Starting with 2.32, GLib enforces this by generating an error
Packit ae235b
when individual headers are directly included.
Packit ae235b

Packit ae235b

Packit ae235b
Still, there are some exceptions; these headers have to be included
Packit ae235b
separately:
Packit ae235b
gmodule.h,
Packit ae235b
glib-unix.h,
Packit ae235b
glib/gi18n-lib.h or
Packit ae235b
glib/gi18n.h (see
Packit ae235b
the Internationalization section),
Packit ae235b
glib/gprintf.h and
Packit ae235b
glib/gstdio.h
Packit ae235b
(we don't want to pull in all of stdio).
Packit ae235b

Packit ae235b
Packit ae235b
Packit ae235b
Packit ae235b

Generated by GTK-Doc V1.27
Packit ae235b
</body>
Packit ae235b
</html>