最近在学习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的机器上实验了一下,也能跑通。
阅读(5873) | 评论(0) | 转发(0) |