Ubuntu 14.04 Desktop

I installed the gtk 2.0 dev package using apt-get. I see the header files in /usr/include are inside a directory gtk-2.0 (/usr/include/gtk-2.0) instead of the root include directory. The umbrella header gtk.h includes lots of other headers by path assuming it is in the root. Therefore, all the references to header files are broken. If I include the gtk.h by including gtk-2.0/gtk/gtk.h then I get file not found for all the includes inside gtk.h.

What is the best way to handle this? Obviously I can move all the headers into the root include directory and into folders as the files expect them (seems like this should have been done by install). Or, I can edit all the header files manually to fix the paths (seems like a real pain). What is the best practice for working with these files? Should I make a local copy and add local paths to my include path?

I'm sure there was a reason for this file layout by the install, but I can't think of what it might be? Any guidance about best practice here would be appreciated.


The proper way to solve this would be to add in -I/usr/include/gtk-2.0 as part of the compile command. However, ideally, this isn't directly included. Instead, the pkg-config tool can provide the CFLAGS to add and the libraries to link to (in the ld command) for the required libraries.

The libgtk2.0-dev package ships with 5 different pkg-config files: gtk+-x11-2.0.pc, gtk+-unix-print-2.0.pc, gtk+-2.0.pc, gdk-2.0.pc, and gdk-x11-2.0.pc. To use the gtk+-2.0.pc one, run pkg-config gtk+-2.0 --cflags to get the CFLAGS and pkg-config gtk+-2.0 --libs to get the flags for ld.

| improve this answer | |
  • Thank you for the explanation. I was thinking more about it and wondering if this structure was maintained by the install to allow for multiple versions of the gtk dev libraries to be installed side-by-side. Then one could just add a ln -s in the root include directory to the version one is using. Could this be the case? Also, I thought pkg-config was part of the install process, is that not the case? – iojedi Jul 20 '14 at 16:45
  • In any case, your solution worked for me. I simply used the output of pkg-config and supplied the paths to my compiler/linker in the makefile. – iojedi Jul 20 '14 at 17:01
  • Regarding the multiple versions, possibly, but headers aren't usually symlinked. Also, please click on the checkmark to mark this answer as accepted. – saiarcot895 Jul 20 '14 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.