Skip to main content
Jump to: navigation, search

SWT/Devel/Gtk/pkg-config compiled GTK

< SWT‎ | Devel‎ | Gtk

Getting started

Sometimes it's necessary to write native GTK snippets to reproduce issues that could be bugs in GTK itself. Of course, it's also important to be able to test these snippets across multiple versions of GTK, specifically GTK3. As a prerequisite, please see the article about compiling GTK. After you've compiled your version of GTK and have a .libs directory, proceed to the next step.

Compiling GTK applications using system GTK

GTK compiles its applications using information from pkg-config. pkg-config has rule files that it uses to store information about the program's needs. These files are located in:


Compiling an ordinary GTK application using your system GTK is easy. Follow the steps here and you are done: But compiling a GTK application using your "custom" compiled GTK libraries requires modification of the pkg-config rule files.

Modifying pkg-config rule files

Navigate to the following directory:


Using sudo/elevated permissions, make a copy of the gdk-3.0.pc and gtk+-3.0.pc files. You'll want to have a backup in case something goes wrong. Note: if you want use modified libraries for other GTK dependencies (like Cairo, Pixman, etc.), you can find those rules files as well.

Next, we are going to edit them. The default gtk+-3.0.pc file should look like this:

targets=x11 broadway wayland
Name: GTK+
Description: GTK+ Graphical UI Library
Version: 3.18.2
Requires: gdk-3.0 atk >= 2.15.1 cairo >= 1.14.0 cairo-gobject >= 1.14.0 gdk-pixbuf-2.0 >= 2.30.0 gio-2.0 >= 2.45.8
Requires.private: atk atk-bridge-2.0 wayland-client >= 1.5.91 xkbcommon >= 0.2.0 wayland-cursor >= 1.5.91 wayland-egl  epoxy >= 1.0 pangoft2 gio-unix-2.0 >= 2.45.8
Libs: -L${libdir} -lgtk-3
Cflags: -I${includedir}

We will need to edit two lines: libdir, and includedir. Libdir should be set to the directory that the compiled .libs folder sits in. The includedir value should reflect the root of your compiled GTK. For example:

 includedir=<location to compiled folder>/gtk/gtk
 libdir=<location to compiled folder>/gtk

The libdir value needs to be changed for gdk-3.0.pc, but the includedir can remain the same:

 includedir=<location to compiled folder>/gtk/gdk
 libdir=<location to compiled folder>/gtk

Compiling with after pkg-config modifications

After you've modified the necessary .pc files, compile your application as usual using pkg-config. The compilation will now use the .SO files from the compiled GTK version, not the ones on your system.

Back to the top