2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
5 <refentry id="gtk-compiling">
7 <refentrytitle>Compiling GTK+ Applications</refentrytitle>
8 <manvolnum>3</manvolnum>
9 <refmiscinfo>GTK Library</refmiscinfo>
13 <refname>Compiling GTK+ Applications</refname>
15 How to compile your GTK+ application
20 <title>Compiling GTK+ Applications on UNIX</title>
23 To compile a GTK+ application, you need to tell the compiler where to
24 find the GTK+ header files and libraries. This is done with the
25 <literal>pkg-config</literal> utility.
28 The following interactive shell session demonstrates how
29 <literal>pkg-config</literal> is used (the actual output on
30 your system may be different):
32 $ pkg-config --cflags gtk+-3.0
33 -pthread -I/usr/include/gtk-3.0 -I/usr/lib64/gtk-3.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12
34 $ pkg-config --libs gtk+-3.0
35 -pthread -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0
39 The simplest way to compile a program is to use the "backticks"
40 feature of the shell. If you enclose a command in backticks
41 (<emphasis>not single quotes</emphasis>), then its output will be
42 substituted into the command line before execution. So to compile
43 a GTK+ Hello, World, you would type the following:
45 $ cc `pkg-config --cflags --libs gtk+-3.0` hello.c -o hello
50 Deprecated GTK+ functions are annotated to make the compiler
51 emit warnings when they are used (e.g. with gcc, you need to use
52 the -Wdeprecated-declarations option). If these warnings are
53 problematic, they can be turned off by defining the preprocessor
54 symbol %GDK_DISABLE_DEPRECATION_WARNINGS by using the commandline
55 option <literal>-DGDK_DISABLE_DEPRECATION_WARNINGS</literal>
59 GTK+ deprecation annotations are versioned; by defining the
60 macros %GDK_VERSION_MIN_REQUIRED and %GDK_VERSION_MAX_ALLOWED,
61 you can specify the range of GTK+ versions whose API you want
62 to use. APIs that were deprecated before or introduced after
63 this range will trigger compiler warnings.
67 Here is how you would compile hello.c if you want to allow it
68 to use symbols that were not deprecated in 3.2:
70 $ cc -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_2 `pkg-config --cflags --libs gtk+-3.0` hello.c -o hello
75 And here is how you would compile hello.c if you don't want
76 it to use any symbols that were introduced after 3.4:
78 $ cc -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_4 `pkg-config --cflags --libs gtk+-3.0` hello.c -o hello
83 The older deprecation mechanism of hiding deprecated interfaces
84 entirely from the compiler by using the preprocessor symbol
85 GTK_DISABLE_DEPRECATED is still used for deprecated macros,
86 enumeration values, etc. To detect uses of these in your code,
87 use the commandline option <literal>-DGTK_DISABLE_DEPRECATED</literal>.
88 There are similar symbols GDK_DISABLE_DEPRECATED,
89 GDK_PIXBUF_DISABLE_DEPRECATED and G_DISABLE_DEPRECATED for GDK, GdkPixbuf and
94 If you want to make sure that your program doesn't use any functions which
95 may be problematic in a multihead setting, you can define the preprocessor
96 symbol GDK_MULTIHEAD_SAFE by using the command line option
97 <literal>-DGTK_MULTIHEAD_SAFE=1</literal>.
101 Similarly, if you want to make sure that your program doesn't use any
102 functions which may be problematic in a multidevice setting, you can
103 define the preprocessor symbol GDK_MULTIDEVICE_SAFE by using the command
104 line option <literal>-DGTK_MULTIDEVICE_SAFE=1</literal>.
108 <title>Useful autotools macros</title>
111 GTK+ provides various macros for easily checking version and backends
112 supported. The macros are
115 <term>AM_PATH_GTK_3_0([minimum-version], [if-found], [if-not-found], [modules])</term>
116 <listitem>This macro should be used to check that GTK+ is installed
117 and available for compilation. The four arguments are optional, and
118 they are: <emphasis>minimum-version</emphasis>, the minimum version
119 of GTK+ required for compilation; <emphasis>if-found</emphasis>, the
120 action to perform if a valid version of GTK+ has been found;
121 <emphasis>if-not-found</emphasis>, the action to perform if a valid
122 version of GTK+ has not been found; <emphasis>modules</emphasis>, a
123 list of modules to be checked along with GTK+.</listitem>
126 <term>GTK_CHECK_BACKEND([backend-name], [minimum-version], [if-found], [if-not-found])</term>
127 <listitem>This macro should be used to check if a specific backend
128 is supported by GTK+. The <emphasis>minimum-version</emphasis>,
129 <emphasis>if-found</emphasis> and <emphasis>if-not-found</emphasis>
130 arguments are optional.</listitem>