在ubuntu中,如果只是安装好gtk+后,用命令行编译的时候总是很麻烦,需要gcc `pkg-config --cflags --libs gtk+-3.0`类似的命令,所以为了方便,就想着在codeblocks下直接编译。
一跑发现会报gtk/gtk.h找不到的问题。在网上搜了下,中文帖子的解决方法只有
http://somuchhope.blog.163.com/blog/static/8995126420121744327801/
但是或许是因为版本的问题,这篇文章中的解决方法对我无效。
所以在stackoverflow搜了下,果然没有让我失望,让我找到了答案,具体见:
http://stackoverflow.com/questions/5921460/how-to-setup-gtk-to-develop-with-codeblocks-on-ubuntu-linux
Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options
`pkg-config --cflags gtk+-3.0`
and add this to Global Compiler Settings > Linker Settings > Other Options
`pkg-config --libs gtk+-3.0`
With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0
另外,刚刚配好才发现的,codeblocks在建新工程的时候,有gtk proj可选。发现如果在新建的时候直接选择gtk proj,那么新建的proj中会自带一个depend文件,里面的内容是对引入对gtk包的依赖。如此一来,哪怕删掉上述的配置也能直接编译运行。