各位走过路过的大侠,小弟今日刚开始学习linux,遇到了glib库的问题,折磨我好些天了。
问题如下:我用的ubuntu9.10,安装的新立得自带的gcc-4.4.1,下载gettext-0.14.5.tar.gz,解压
安装时./configure --prefix=/usr,make,sudo make install显示正确安装。下载glib-2.12.1.tar.bz2,解压安装时./configure --prefix=/usr,make,sudo make install显示正确安装。然后我在myproject目录下用vim编写了一个简单的测试glib库的程序test.c:
#include <stdio.h>
#include <glib.h>
#include <glib/gprintf.h>
void main()
{
gchar ch[128];
g_sprintf(ch, "hello world");
printf("g_strup(ch)\n");
}
但我在用gcc编译时:
$ gcc -o test test.c,提示没有glib.h和gprintf.h文件和目录
然后我用如下编译
$gcc test.c -I/usr/include/glib-2.0 -L/usr/lib/glib-2.0 -o test,却又冒出很多错误,最后部分截图如下
.......
/usr/include/glib-2.0/glib/gtree.h:77: error: expected ‘)’ before ‘*’ token
/usr/include/glib-2.0/glib/gtree.h:80: error: expected ‘)’ before ‘*’ token
/usr/include/glib-2.0/glib/gtree.h:81: error: expected ‘)’ before ‘*’ token
In file included from test.c:3:
/usr/include/glib-2.0/glib/gprintf.h:28: error: expected ‘)’ before ‘const’
/usr/include/glib-2.0/glib/gprintf.h:31: error: expected declaration spec
/usr/include/glib-2.0/glib/gprintf.h:32: error: format string argument not a string type
/usr/include/glib-2.0/glib/gprintf.h:33: error: expected ‘)’ before ‘*’ token
/usr/include/glib-2.0/glib/gprintf.h:37: error: expected ‘)’ before ‘const’
/usr/include/glib-2.0/glib/gprintf.h:40: error: expected declaration specifiers or ‘...’ before ‘gchar’
/usr/include/glib-2.0/glib/gprintf.h:41: error: expected declaration specifiers or
/usr/include/glib-2.0/glib/gprintf.h:42: error: expected ‘)’ before ‘*’ token
/usr/include/glib-2.0/glib/gprintf.h:45: error: expected ‘)’ before ‘*’ token
test.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
/usr/include/glib-2.0/glib/gmem.h:47: error: old-style parameter declarations in prototyped function definition
test.c:9:error: expected ‘{’ at end of in:42:7
运行$gcc test.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -o test 也是冒出以上错误
运行$gcc test.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -l/glib-2.0 -o test 也是冒出以上错误
安装glib库时是用的./configure --prefix=/usr,安装完后,在/usr/lib/目录下有个glib-2.0的文件夹,该文件夹里只有一个include文件夹,include的文件夹里只有一个glibconfig.h文件。在/usr/include/文件夹里也有一个glib-2.0的文件夹glib.h等头文件。我现在怀疑的是我的glib库是否真的安装上了,但我也不知道怎么判断。希望各位能帮忙解释一下,谢谢了。
求救有关glib编译链接问题
-
- 帖子: 4
- 注册时间: 2010-04-21 0:40
- HuntXu
- 帖子: 5776
- 注册时间: 2007-09-29 3:09
Re: 求救有关glib编译链接问题
代码: 全选
gcc test.c `pkg-config glib-2.0 --cflags --libs` -o test
代码: 全选
#include <glib.h>
#include <glib/gprintf.h>
int main()
{
gchar ch[128];
g_sprintf(ch, "hello world");
g_printf("%s\n", g_strup(ch));
return 0;
}
HUNT Unfortunately No Talent...
- HuntXu
- 帖子: 5776
- 注册时间: 2007-09-29 3:09
Re: 求救有关glib编译链接问题
g_strup has been deprecated since version 2.2 and should not be used in newly-written code. This function is totally broken for the reasons discussed in the g_strncasecmp() docs - use g_ascii_strup() or g_utf8_strup() instead.
HUNT Unfortunately No Talent...
-
- 帖子: 32
- 注册时间: 2010-11-29 17:23
Re: 求救有关glib编译链接问题
简单易懂。谢谢2楼