GTK FAQ Introduction

Материал из Wiki.crossplatform.ru

Версия от 08:13, 19 марта 2009; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Содержание

Introduction to GTK+

About this tutorial

This is an introductory GTK+ programming tutorial. The tutorial is targeted for the C programming language. It has been created and tested on Linux. The GTK+ programming tutorial is suited for novice and intermediate programmers.

GTK+

<img src="../images/gtk.png" style="float: left; margin-right:10px">

The GTK+ is a library for creating graphical user interfaces. The library is created in C programming language. The GTK+ library is also called the GIMP Toolkit. Originally, the library was created while developing the GIMP image manipulation program. Since then, the GTK+ became one of the most popular toolkits under Linux and BSD Unix. Today, most of the GUI software in the open source world is created in Qt or in GTK+. The GTK+ is an object oriented application programming interface. The object oriented system is created with the Glib object system, which is a base for the GTK+ library. The GObject also enables to create language bindings for various other programming languages. Language bindings exist for C++, Python, Perl, Java, C# and other programming languages.

The GTK+ itself depends on the following libraries.

  • Glib
  • Pango
  • ATK
  • GDK
  • GdkPixbuf
  • Cairo

The Glib is a general purpose utility library. It provides various data types, string utilities, enables error reporting, message logging, working with threads and other useful programming features. The Pango is a library which enables internationalization. The ATK is the accessibility toolkit. This toolkit provides tools which help physically challenged people work with computers. The Cairo is a library for creating 2D vector graphics. It has been included in GTK+ since version 2.8.

Gnome and XFce desktop environments have been created using the GTK+ library. SWT and wxWidgets are well known programming frameworks, that use GTK+. Prominent software applications that use GTK+ include Firefox or Inkscape.

Compiling GTK+ applications

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.

Sources