gtk 与 gtkglext的安装比较麻烦,装好gtk2.0之后,还要装opengl的库:
sudo apt-get install mesa-common-dev mesademos libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev
之后再装gtkglext。
用eclipse cdt开发的话需要在 项目的properties -> C/C++ Build -> Settings 中做如下配置:
(1)Compiler->Miscellaneous->在Other flags中添上"`pkg-config --cflags gtk+-2.0` `pkg-config --cflags gtkglext-1.0-lGL -lglut`"(双引号内部内容,不算双引号)。注意这个"`"是esc键下面那个符号,不是单引号。
(2)Linker->Miscellaneous->在Linker flags中添上"`pkg-config --libs gtk+-2.0` `pkg-config --libs gtkglext-1.0`-lGL -lglut"(双引号内部内容,不算双引号)。注意这个"`"是esc键下面那个符号,不是单引号。
(3) Compiler->Include paths中添加 gtk,gtkglext ,glib头文件路径。主要是为了消除拼写错误。各自的安装路径可能不一样,我的是:
/usr/local/include/gtk-2.0
/usr/local/include/gtkglext-1.0
/usr/include/glib-2.0
这样配置好之后,应该就可以了。但是还有可能有问题,于是找到了下面一篇文章。
原文链接:http://yuxu9710108.blog.163.com/blog/static/237515342007216114727195/
`pkg-config --libs gtk+-2.0`: 成功
[yuxu@yx wxqView]$ 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/freetype2 -I/usr/include/libpng12
`pkg-config --libs gtkglext-1.0`:失败
[yuxu@yx wxqView]$ pkg-config --cflags gtkglext-1.0
Package gtkglext-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkglext-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkglext-1.0' found
在Makefile中应用'pkg-config --cflags gtkglext-1.0`导致失败:
[yuxu@yx ~]$ cd projects/bilchecker/wxqView/
[yuxu@yx wxqView]$ ls
DemFactoryBIL.cpp Doxyfile G49G001049.hdr dem.h rism_utils.h
DemFactoryBIL.h G49G001049.MAT Makefile demView.cpp wan.log
DemGLAdapter.cpp G49G001049.bil Statistics.h makefile.win
DemGLAdapter.h G49G001049.blw WkbParser.h rism_utils.cpp
[yuxu@yx wxqView]$ make
g++ -pipe -O3 -c `pkg-config --cflags gtkglext-1.0` -o demView.o demView.cpp
Package gtkglext-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkglext-1.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkglext-1.0' found
demView.cpp:18:21: error: gtk/gtk.h: No such file or directory
demView.cpp:19:28: error: gdk/gdkkeysyms.h: No such file or directory
demView.cpp:20:23: error: gtk/gtkgl.h: No such file or directory
demView.cpp:21:28: error: gdk/gdkglglext.h: No such file or directory
demView.cpp:31:21: error: GL/glut.h: No such file or directory
demView.cpp: In member function 'void DemView::showAxies(float, float)':
demView.cpp:158: error: 'glutSolidSphere' was not declared in this scope
demView.cpp: At global scope:
demView.cpp:193: error: expected initializer before '*' token
demView.cpp:194: error: expected initializer before '*' token
demView.cpp:195: error: expected initializer before '*' token
demView.cpp:234: error: 'gboolean' does not name a type
demView.cpp:271: error: 'gboolean' does not name a type
demView.cpp:299: error: 'gboolean' does not name a type
demView.cpp:330: error: 'gboolean' does not name a type
demView.cpp:357: error: 'gboolean' does not name a type
demView.cpp:461: error: expected initializer before '*' token
demView.cpp:542: error: expected initializer before '*' token
make: *** [demView.o] Error 1
1。 使用locate XXX.pc来查看其所在的文件夹:
[yuxu@yx wxqView]$ locate gtkglext-1.0.pc
/home/yuxu/gtkglext-1.2.0/gtkglext-1.0.pc
/home/yuxu/soft/gtkglext-1.0.6/gtkglext-1.0.pc
/usr/local/lib/pkgconfig/gtkglext-1.0.pc
[yuxu@yx wxqView]$ locate gtk+-2.0
/usr/lib/pkgconfig/gtk+-2.0.pc
发现是XXX.pc文件所在的路径不对gtk+2.0的XX.pc文件 在/usr/lib下,而
gtkglext-1.0的xx.pc文件在/usr/local/lib下,所以pkg-config能找到gtk+-2.0,
而找不到gtkglext-1.0,而 PKG_CONFIG_PATH,的default search path为/usr/lib,
这个关系到gtkglext-1.0编译的重要的gtkglext-1.0.pc文件却在/usr/local/lib下,
当然找不到
解决方法:
export PKG_CONFIG_PATH = /usr/local/pkgconfig(最好写入.bash_profile 中去)
即可让`pkg-config --libs gtkglext-1.0`这条命令找到gtkglext-1.0.pc文件。
检测gtkglext-1.0,gtk+-1.0成功安装与否的方法:
运行以下命令:
pkg-config --cflags gtkglext-1.0
pkg-config --cflags gtk+-2.0
成功显示各个头文件,库文件路径,则OK!在Makefile,GCC编译时,加上上面的命令即可以
正常使用这些库了。