子目录中的头文件(例如GTK / gtk.h VS GTK的2.0 / GTK / gtk.h) [英] Header files in subdirectories (e.g. gtk/gtk.h vs gtk-2.0/gtk/gtk.h)
问题描述
我试图建立使用GTK,其中包括该行一个Hello World:
I'm trying to build a hello world using GTK, which includes the line:
#include <gtk/gtk.h>
你所期望的。
提供的Makefile中有一行:
The Makefile supplied has the line:
GTK_INCLUDE = -I/usr/local/include
所以希望找到gtk.h在/usr/local/include/gtk/gtk.h。但是我的系统上,它位于/usr/local/include/gtk-2.0/gtk/gtk.h,即version'ed子目录中。
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.
显然,在这种情况下,我可以添加-I在/ usr /本地/包括/ GTK的2.0 Makefile文件,但同样的问题gtk.h的依赖作物和等。
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.
是否有处理这个问题的好办法?可以配置用于定位所在的头文件,并添加相应的include目录?我知道旁边的一无所知配置,但似乎要找出事情有关系统在构建时,这就是我所追求的。
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?
感谢您的指点!
推荐答案
您需要使用 pkg配置
来获得包括路径:
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.)
这篇关于子目录中的头文件(例如GTK / gtk.h VS GTK的2.0 / GTK / gtk.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!