怎样装GTK+的库

开发基于GTK+或QT的应用程序
回复
头像
gre_linewer
帖子: 180
注册时间: 2006-11-22 10:57
送出感谢: 0
接收感谢: 0
联系:

怎样装GTK+的库

#1

帖子 gre_linewer » 2007-03-03 23:38

看一本书上的GTK+/GNOME程序如下:
#include<gtk/gtk.h>

/*==============Prototypes=================*/
gint CloseRequest(GtkWidget *theWindow,gpointer data);
gint main(gint argc, gchar * argv[])
{
GtkWidget *window;
/*Get Gtk+ to process the startup arguments */
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(CloseRequest),NULL);
gtk_widget_show(window);
gtk_main();
return 0;
}
void CloseRequest (GtkWidget *theWindow,gpointer data)
{
gtk_main_quit();
}


然后运行gcc -o intro intro.c `gtk-config --cflags --libs`
照书上说应该得到一个窗口.可是出现如下东西
bash: gtk-config: command not found
gcc: -E required when input is from standard input
intro.c:1:20: gtk/gtk.h: No such file or directory
intro.c:4: error: syntax error before "CloseRequest"
intro.c:4: error: syntax error before '*' token
intro.c:4: warning: data definition has no type or storage class
intro.c:5: error: syntax error before "main"
intro.c:5: error: syntax error before "argc"
intro.c: In function `main':
intro.c:7: error: `GtkWidget' undeclared (first use in this function)
intro.c:7: error: (Each undeclared identifier is reported only once
intro.c:7: error: for each function it appears in.)
intro.c:7: error: `window' undeclared (first use in this function)
intro.c:9: error: `argc' undeclared (first use in this function)
intro.c:9: error: `argv' undeclared (first use in this function)
intro.c:10: error: `GTK_WINDOW_TOPLEVEL' undeclared (first use in this function)
intro.c:11: error: `NULL' undeclared (first use in this function)
intro.c: At top level:
intro.c:16: error: syntax error before '*' token
intro.c:17: error: conflicting types for `CloseRequest'
intro.c:4: error: previous declaration of `CloseRequest'
我想应该是我没装含gtk/gtk.h的GTK+库.
应该怎样装GTK+的库
Ubuntu 8.04
IBM R52-18465DC
CPU:PM 1.73Ghz DDR2:768MB 533Mhz
INTEL 915GM/915PM
ATI Mobility Radeon X300 64MB
40G SATA
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System
送出感谢: 0
接收感谢: 0

#2

帖子 5451vs5451 » 2007-03-04 0:09

应该是
gcc -o intro intro.c `pkg-config gtk+-2.0 --cflags --libs`

查了一下gtk-config是gtk1.2里的东东。
头像
gre_linewer
帖子: 180
注册时间: 2006-11-22 10:57
送出感谢: 0
接收感谢: 0
联系:

#3

帖子 gre_linewer » 2007-03-05 22:56

我运行gcc -o intro intro.c `pkg-config gtk+-2.0 --cflags --libs` 之后
dolphin9@dolphin9-laptop:~/C$ gcc -o intro intro.c `pkg-config gtk+-2.0 --cflags --libs`
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
intro.c:1:20: error: gtk/gtk.h: No such file or directory
intro.c:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘CloseRequest’
intro.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘main’
intro.c:13: error: expected ‘)’ before ‘*’ token
intro.c:16: error: expected identifier or ‘(’ before ‘}’ token

我在/usr/lib/中有gtk-2.0 ,把gtk+-2.0换成gtk-2.0也不行。
另外,根据提示,要修改pkg-config的配置文件加入包含gtk+-2.0.pc的目录,
lS兄弟还能告诉配置文件在呢,我没找到
gtk.h也没找到
Ubuntu 8.04
IBM R52-18465DC
CPU:PM 1.73Ghz DDR2:768MB 533Mhz
INTEL 915GM/915PM
ATI Mobility Radeon X300 64MB
40G SATA
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System
送出感谢: 0
接收感谢: 0

#4

帖子 5451vs5451 » 2007-03-06 0:36

apt-get install libgtk2.0-dev
头像
gre_linewer
帖子: 180
注册时间: 2006-11-22 10:57
送出感谢: 0
接收感谢: 0
联系:

#5

帖子 gre_linewer » 2007-03-06 16:52

谢谢5451vs5451
apt-get install libgtk2.0-dev就好了
Ubuntu 8.04
IBM R52-18465DC
CPU:PM 1.73Ghz DDR2:768MB 533Mhz
INTEL 915GM/915PM
ATI Mobility Radeon X300 64MB
40G SATA
头像
gre_linewer
帖子: 180
注册时间: 2006-11-22 10:57
送出感谢: 0
接收感谢: 0
联系:

#6

帖子 gre_linewer » 2007-03-06 21:41

请教下5451vs5451:
开发gtk+程序要通过libgtk2.0-dev(好象自动也安装上了include头文件)安装gtk库,
类似的,开发qt程序,也要安装对应的qt库是么?
Ubuntu 8.04
IBM R52-18465DC
CPU:PM 1.73Ghz DDR2:768MB 533Mhz
INTEL 915GM/915PM
ATI Mobility Radeon X300 64MB
40G SATA
头像
titainium
帖子: 689
注册时间: 2006-12-02 12:25
送出感谢: 0
接收感谢: 0

#7

帖子 titainium » 2007-03-08 20:09

libgtk2.0-dev其实是安装一堆头文件之类的东西,库文件就是libgtk,你的报错信息其实一上来就说了,找不到那个头文件。
Titainium
Unixnewbie
帖子: 1
注册时间: 2009-08-15 15:20
送出感谢: 0
接收感谢: 0

Re: 怎样装GTK+的库

#8

帖子 Unixnewbie » 2009-08-15 15:24

我也遇到过这样的问题,试试 gcc $(pkg-config --cflags --libs gtk+-2.0) -o intro intro.c
头像
cnkilior
论坛版主
帖子: 4979
注册时间: 2007-08-05 17:40
送出感谢: 0
接收感谢: 5 次

Re: 怎样装GTK+的库

#9

帖子 cnkilior » 2009-08-15 15:32

好好看gtk-tutorial
回复

回到 “GTK+和QT”