Subdirectory header files (e.g. gtk / gtk.h vs gtk-2.0 / gtk / gtk.h)

I am trying to build a hello world using GTK, which includes a line:

#include <gtk/gtk.h> 

as expected.

There is a line in the attached Makefile:

 GTK_INCLUDE = -I/usr/local/include 

so he 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, that is, inside the version subdirectory.

Obviously, in this case I can add -I / usr / local / include / gtk-2.0 to the Makefile, but the same problem arises with gtk.h dependencies, etc.

Is there a good way to handle this? Could the configuration be used to locate the header files and add the appropriate include directories? I don’t know anything about customization, but it seems that he learns about the system during the build, which I do afterwards.

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

Thanks for any pointers!

+4
source share
3 answers

You need to use pkg-config to get the included 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 should 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 depend on your distribution and will always be correct for your distribution.)

+8
source

Perhaps you should create a symbolic link, for example:

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

but first you can try reinstalling the GTK package.

+4
source

I have not used gtk for a long time, but as a rule, on Linux, this is what there is a script called packagename-config (in this case, probably gtk-config) that comes with the development of the headers your make file should make Get the correct included 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 reverse steps, not the apostrophe)

And you probably also want to add the output of gtk-config --libs to your LDFLAGS to make sure that you bind all the right things.

+2
source

Source: https://habr.com/ru/post/1286716/


All Articles