全部博文(2005)
分类: LINUX
2008-08-21 13:43:44
首先获得超级用户权限
apt-get install vim #使用vim来编写代码,当然您可以使用任何自己喜欢的编辑器
apt-get install build-essential #这将安装gcc/g++/gdb/make 等基本编程工具
apt-get install gnome-core-devel #这将安装 libgtk2.0-dev libglib2.0-dev 等开发相关的库文件
apt-get install pkg-config #用于在编译GTK程序时自动找出头文件及库文件位置
apt-get install devhelp #这将安装 devhelp GTK文档查看程序
apt-get install libglib2.0-doc libgtk2.0-doc #这将安装 gtk/glib 的API参考手册及其它帮助文档
apt-get instal glade libglade2-dev #这将安装基于GTK的界面构造程序
都是安装好后测试一下程序hello.c
#include
void hello(GtkWidget *widget,gpointer data)
{
g_print("Hello 大家好\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 大家好");
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);
}
最后编译运行:
$ gcc hello.c -o hello `pkg-config --cflags --libs gtk+-2.0`
$ . /hello