1.命令行安装命令:
方法一:
安装命令:
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 |
方法二:
安装命令:
2.设置环境变量 PKG_CONFIG_PATH
安装完了之后,按理来说,我们可以使用测试程序对其进行相关功能测试了。但是这个时候肯定会报错。因为一个非常关键的环境变量我们还没有进行设置:
PKG_CONFIG_PATH,这个环境变量中必须包含我们的 glib,pango,gthread的路径。
1)首先我们更新软件数据库。updatedb(注意这一步很重要,要不你很可能定位不到需要的文件)
2)定位gtk+-2.0.pc,pango.pc,pthread-stubs.pc的位置:locate gtk+-2.0.pc;locate pango.pc;locate pthread-stubs.pc (注意这儿可能是定位不到一些,没关系,我们只要不用后缀名,只把前面的文件名定位到也可以的)
3)定义环境变量:
结合前篇文章-—ubuntu中的环境变量。
在本文中,我们给单一用户进行环境变量的设置,于是操作如下:
打开当前用户的环境变量配置文件:vi ~/.bashrc
在文件中添加: PKG_CONFIG_PATH =" path1:path2:path3 "
export PATH
下面是一个测试程序:
gtktest.c程序
点击(此处)折叠或打开
-
//Helloworld.c
-
#include <gtk/gtk.h>
-
-
int main(int argc,char *argv[])
-
{
-
GtkWidget *window;
-
GtkWidget *label;
-
-
gtk_init(&argc,&argv);
-
-
/* create the main, top level, window */
-
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
-
/* give it the title */
-
gtk_window_set_title(GTK_WINDOW(window),"Hello
World");
-
-
/* connect the destroy signal of the window to gtk_main_quit
-
* when the window is about to be
destroyed we get a notification and
-
* stop the main GTK+ loop
-
*/
-
g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
-
-
/* create the "Hello, World" label */
-
label = gtk_label_new("Hello, World");
-
-
/* and insert it into the main window */
-
gtk_container_add(GTK_CONTAINER(window),label);
-
-
/* make sure that everything, window and label, are
visible */
-
gtk_widget_show_all(window);
-
-
/* start the main loop, and let it
rest until the application is closed */
-
gtk_main();
-
-
return 0;
- }
$ gcc `pkg-config --cflags --libs gtk+-2.0` gtktest.c -o gtktest $ ./gtktest注意:‘ ’符号不是我们的单引号,而是Esc按键下面的那个按键,很容易出错
会显示一个带有一个按钮的窗口,点击按钮以后窗口关闭,命令行显示Hello world!