一、开发环境
Ubuntu 12.04 + Eclipse Cpp
二、环境配置
1、安装GTK2.0
sudo apt-get install gnome-core-devel build-essential libgtk2.0-dev libgtk2.0-doc
2、配置GTK工程
(1)创建C Project
(2)右键点击工程,Properties --> C/C++Build --> Settings
修改编译命令,点击GCC C Compiler,将Command Line Pattern 修改为一下值:
${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT}
添加头文件引用,点击GCC C Compiler-->Includes,添加如下目录:
/usr/include/gtk-2.0/usr/include/glib-2.0
增加编译参数,点击GCC C Compiler-->Miscellaneous,添加如下参数:
`pkg-config --cflags gtk+-2.0`
修改链接命令,点击GCC C Linker,将Command Line Pattern 修改为一下值:
${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT}
增加链接参数,点击GCC C Linker-->Miscellaneous,添加如下参数:
`pkg-config --libs gtk+-2.0`
3、测试开发环境
编译运行以下代码
#includeint main( int argc, char *argv[] ){ GtkWidget *window; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); gtk_main (); return 0;}
应该得到如图效果:
参考资料:
http://www.linuxidc.com/Linux/2011-12/49777.htm
https://developer.gnome.org/gtk2/
http://www.huzheng.org/ebook/gtk2-tut/book1.html