How to compilie gtk+ application

Compiling GTK+ program

To compile GTK+ applications, we have a handy tool called pkg-config. The pgk-config returns metadata about installed libraries. Simply put, if we want to use a specific library, it will provide us necessary dependent libraries and include files, that we need. The pkg-config program retrieves information about packages from special metadata files.

gcc -o simple simple.c `pkg-config --libs --cflags gtk+-2.0`

Here we show, how we can compile a simple program. The source code consists of one file, simple.c.

$ pkg-config --cflags gtk+-2.0
-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.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/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12

This list shows all necessary include files for GTK+ programming.

$ pkg-config --libs gtk+-2.0
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0
-lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr
-lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0
-lgmodule-2.0 -ldl -lglib-2.0

And this list shows the necessary libraries.

No comments:

Top Blogs