Tuesday, February 25, 2014

How to solve "Package gtk+-3.0 was not found" & "fatal error: gtk/gtk.h: No such file or directory" errors in Linux

As of now some of the Linux distros don't come up with the gtk-3.0 libraries and development files by default.   Though Gnome application developers are asked to migrate to gtk3, most of the desktop applications are still in gtk2.  Due to these reasons gtk3 development files are not pre bundled with distros.  So, we have to install gtk3 development files, libraries manually to compile a gtk+-3.0 based GUI applications.

If your gtk3 program compilation ($gcc -o executable_name  program_name  `pkg-config --cflags --libs gtk+-3.0`) throws error something like this

Package gtk+-3.0 was not found
            (or)
fatal error: gtk/gtk.h: No such file or directory

which means your machine is not installed with the gtk3 development files.  
To install the package in debian based machines 

$sudo apt-get install libgtk-3-dev

To install in rpm based machines

$yum install gtk3-devel

After the successful installation your machine should return output something like following while you execute the command 
"sudo pkg-config --cflags --libs gtk+-3.0"

"-pthread -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/freetype2 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng12  -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 
"

Now, you can compile your gtk3 programs happily... :)

No comments: