Sunday, November 14, 2010

Compiling GTK+ Programs in Ubuntu

There are easy to follow gtk+ 2.0 tutorials. I learn by referring to the official gnome gtk+ tutorials and from
When compiling most often many of us newbies have got the error: "No such file or directory" even if you have all the gnome-gtk-devel and other required packages. Also you don't need to set any environment variables to make it work.
gcc: pkg-config --cflags --libs  gtk+-2.0: No such file or directory
simple.c:1: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
If that's the case then just see what command you have entered. Most probably you might have entered:
gcc -Wall -g simple.c -o simple 'pkg-config --cflags --libs  gtk+-2.0'
where simple.c is the filename. Note that the quote in which the pkg-config is written is ' character which is near to your Enter key. If so then that's the mistake. The character must be ` which is in the tilde (~) key, above the tab key.
So the correct way will be:
gcc -Wall -g simple.c -o simple `pkg-config --cflags --libs  gtk+-2.0`
The character ` is called 'backtick
If you are still confused with those little nasty quote characters, which makes newbie life miserable you can all together forget about this and use the one shown below:
gcc -Wall -g simple.c -o simple $(pkg-config --cflags --libs  gtk+-2.0)
It does the same thing, outputs the list of files, to be included and linked and likewise. To know more about that you can read the docs.