views:

1029

answers:

3

Hello,

I'm trying to build a hello world using GTK, which includes the line:

#include <gtk/gtk.h>

as you would expect.

The Makefile supplied has the line:

GTK_INCLUDE = -I/usr/local/include

so it would expect to find gtk.h in /usr/local/include/gtk/gtk.h. However on my system, it is located in /usr/local/include/gtk-2.0/gtk/gtk.h, ie within a version'ed subdirectory.

Obviously in this case I can add -I/usr/local/include/gtk-2.0 to the Makefile, but the same problem crops up with gtk.h's dependencies and so on.

Is there a good way of dealing with this? Could configure be used to locate where the header files are and add the appropriate include directories? I know next to nothing about configure, but it seems to find out things about the system at build time, which is what I am after.

Is this a common occurence or do I have some freak directory structure which is the real problem?

Thanks for any pointers!

+3  A: 

Probably, you must create a symbolic link like:

ln -s /usr/local/include/gtk /usr/local/include/gtk-2.0

but you can first try to reinstall the GTK package.

bill
I had thought of this but it didn't seem the right thing to do, especially considering everything else that needs to be changed in the same way.
Ray2k
+2  A: 

I haven't used gtk in a long while, but the way this is normally handled in Linux is that there is a script called packagename-config (in this case, probably gtk-config) that comes with the development headers, which your makefile is supposed to call in order to get the proper include paths and linker flags for the package, using --cflags and --libs respectively.

So try something like

GTK_INCLUDE=`gtk-config --cflags`

(note the use of backticks, not apostrophes)

And you probably also want to add the output of gtk-config --libs to your LDFLAGS in order to make sure you are linking against all the right stuff.

Tyler McHenry
AFAIR, gtk-config has been replaced by the generic pkg-config a long time ago (as have most other uses of packagename-config style scripts).
CesarB
+5  A: 

You need to use pkg-config to get the include paths:

$ 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/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12

You must also use it to get the libraries:

$ pkg-config --libs gtk+-2.0
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0

(The output of these commands will vary depending on your distribution, and will always be the correct ones for your distribution.)

CesarB
Thanks, this looks like what I'm after - I recognise some of the other includes that your pkg-config example creates (like pango) as needing a more specific include directory too.
Ray2k