1. 安装 gtk+2.0
针对RedHat系列操作系统,执行命令
#yum install gtk2-devel
针对Debian系列操作系统(例如Ubunta),执行命令
$sudo apt-get install libgtk2.0-dev
2. Eclipse配置
设置gcc编译参数:
Project->Properties->C/C++ Build->Settings->GCC C Compiler->Miscellaneous->Other Flags->添加`pkg-config --cflags gtk+-2.0`
Project->Properties->C/C++ Build->Settings->GCC C++ Compiler->Miscellaneous->Other Flags->添加`pkg-config --cflags gtk+-2.0`
设置C++链接参数:
Project->Properties->C/C++ Build->Settings->GCC C++ Linker->Miscellaneous->Linker Flags->添加`pkg-config --libs gtk+-2.0` `pkg-config --libs gmodule-2.0`
配置完成,可以编写如下程序进行测试
#include <gtk/gtk.h>
int main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* label;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
label = gtk_label_new("Hello World.");
gtk_container_add(GTK_CONTAINER(window), label);
gtk_widget_show_all(window);
gtk_main();
return 0;
}