$ gcc `apr-config --cflags --libs` apr-skeleton.c -o apr-skeleton
In file included from /usr/include/apr-1.0/apr_general.h:28,
from apr-skeleton.c:12:
/usr/include/apr-1.0/apr.h:270: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘apr_off_t’apr_off_t
typedef off64_t apr_off_t;
# if defined __USE_LARGEFILE64 && !defined __off64_t_defined
typedef __off64_t off64_t;
# define __off64_t_defined
# endif
#ifdef _LARGEFILE64_SOURCE
# define __USE_LARGEFILE64 1
#endif
/tmp/ccdrJW18.o:在函数‘main’中:
/home/ht/docs/apr/apr-tutorial/sample/apr-skeleton.c:22:对‘apr_initialize’未定 义的引用
/home/ht/docs/apr/apr-tutorial/sample/apr-skeleton.c:30:对‘apr_terminate’未定义的引用
collect2: ld returned 1 exit status
$ apr-config --cflags --libs
-pipe -Wall -g -O2 -pthread -luuid -lrt -lcrypt -lpthread -ldl
$gcc -lapr-1 `apr-config --cflags --libs` apr-skeleton.c -o apr-skeleton
Linux version 2.6.18-5-686 (Debian 2.6.18.dfsg.1-17) (dannf@debian.org) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Mon Dec 24 16:41:07 UTC 2007
上面是老版本的解决方案,新的。
新的如下 /usr/local/apr/bin/apr-1-config --cflags --libs --link-ld 生成对应的GCC 编译选项
-g -O2 -pthread -luuid -lrt -lcrypt -lpthread -ldl -L/usr/local/apr/lib -lapr-1
然后gcc -g -O2 -pthread -luuid -lrt -lcrypt -lpthread -ldl -L/usr/local/apr/lib -lapr-1 apr-skeleton.c -o apr-skeleton
注意事项:
在所有实例源代码第一行要加上这句#define _LARGEFILE64_SOURCE 才能解决apr.h 报错。
可能有人会问 apr-1-config是什么,从网上下载apr:http://apr.apache.org/,然后安装。