Chinaunix首页 | 论坛 | 博客
  • 博客访问: 468537
  • 博文数量: 111
  • 博客积分: 2332
  • 博客等级: 大尉
  • 技术积分: 1187
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-29 11:22
文章分类

全部博文(111)

文章存档

2013年(9)

2012年(28)

2011年(17)

2010年(28)

2009年(29)

我的朋友

分类: C/C++

2012-04-26 17:22:24

最近在学习libevent。看了一下libevent源码sample里面的time-test的例子。因为我要部署程序的机器不属于我管,所以环境不确定有libevent。于是就想着把libevent编译的时候静态化了。
一开始cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -static -levent
会报错:
/usr/local/lib/libevent.a(evutil.o): In function `test_for_getaddrinfo_hacks':
/home/guangtong/libevent-2.0.18-stable/evutil.c:1104: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/lib/libevent.a(evutil.o): In function `evutil_unparse_protoname':
/home/guangtong/libevent-2.0.18-stable/evutil.c:757: warning: Using 'getprotobynumber' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/lib/libevent.a(event.o): In function `gettime':
/home/guangtong/libevent-2.0.18-stable/event.c:366: undefined reference to `clock_gettime'
/usr/local/lib/libevent.a(event.o): In function `detect_monotonic':
/home/guangtong/libevent-2.0.18-stable/event.c:336: undefined reference to `clock_gettime'
说明libevent里面自己会调用so文件,但是-static之后,他就不能调用了,所以出的这个错。
于是我就想着怎么样只让libevent本身静态化。想来想去就是也不指定需要调用的库名了,而是直接把所需要的静态库文件全都加入到编译命令里面。
于是:
gcc  -I/usr/local/include -L/usr/local/lib -o time-test time-test.c -lrt /usr/local/lib/libevent.a  /usr/local/lib/libevent_core.a  /usr/local/lib/libevent_core.a  /usr/local/lib/libevent_openssl.a  /usr/local/lib/libevent_pthreads.a
搞定,之后找了一台没有安装libevent的机器上实验了一下,也能跑通。
 
阅读(5799) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~