ubuntu下GTK安装 转载来源 http://blog.163.com/dengwei20071015@126/blog/static/61593913200911993452446/
2009-02-19 21:34:52| 分类:
ubuntu
|字号
要生成C图形界面的程序,得安装GTK环境
安装GTK环境只要安装一个gnome-core-devel就可以了,里面集成了很多其他的包。除此之外还要转一些其他的
东西,如libglib2.0
-doc、libgtk2.0-doc帮助文档,devhelp帮助文档查看,glade-gnome、glade-common、glade-doc图
形界面设计等。
代码:
sudo apt-get install gnome-core-devel
sudo apt-get install libglib2.0-doc libgtk2.0-doc
sudo apt-get install devhelp
sudo apt-get install glade-gnome glade-common glade-doc
写个测试程序,全是抄别人的,相当于windows下的SDK了。
记事本编写,终端命令编译:
#include
void hello(GtkWidget *widget,gpointer data)
{
g_print("Hello Ubuntu!\n");
}
gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{
g_print ("delete event occurred\n");
return(TRUE);
}
void destroy(GtkWidget *widget,gpointer data)
{
gtk_main_quit();
}
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
gtk_init (&argc, &argv);
window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(delete_event),NULL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",GTK_SIGNAL_FUNC (destroy), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
button = gtk_button_new_with_label ("Hello Ubuntu!");
gtk_signal_connect (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (hello), NULL);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (gtk_widget_destroy),GTK_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window); /*显示一个窗口*/
gtk_main(); /*进入主循环*/
return(0);
}
保存为:gtkhello.c
用下面命令编译运行
代码:
$ gcc gtkhello.c -o gtktest `pkg-config --cflags --libs gtk+-2.0`
$ ./gtktest
阅读(1212) | 评论(0) | 转发(0) |