gtk,gtkglext安裝與eclipse cdt配置

 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編譯時,加上上面的命令即可以
正常使用這些庫了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章