Wednesday, August 18, 2010

My first usage of GTK!

Today I used the GTK for the first time. So what is GTK? GTK expands to GIMP ToolKit. GTK is the library to build graphical user interfaces. It is called GIMP ToolKit because, originally it was developed for the program GIMP (GNU Image Manipulation Program). Now many programs are using it.

I installed GTK in my ubuntu-9.10 desktop. With build essentials already with my system, I issued the following command at the terminal to install GTK+-2.0:

sudo apt-get install libgtk2.0-dev libgtk2.0-doc devhelp

libgtk2.0-dev installs the GTK library. libgtk2.0-doc and devhelp installs the documents of GTK and the browser for the documents respectively.

I wrote a simple hello world program. The program was written to create a window with a button on it. The button would have the label "Hello, World! Bye...". And once the button is clicked, the application would quit.

Download: helloworld_gtk.c

Compiled the hello world program and built the executable for the same by issuing the following command at the terminal:

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

Here,
  1. pkg-config is the program that reads the .pc which comes with GTK to determine what compiler switches are needed to compile programs that use GTK.
  2. pkg-config --cflags gtk+-2.0 will output a list of include directories for the compiler to look in
  3. pkg-config --libs gtk+-2.0 will output the list of libraries for the compiler to link with and the directories to find them in.

No comments: