【原创】源码编译libevent-2.0.21-stable生成库文件说明

按照 README 中的说明,首先执行 configure
下面的输出信息是针对源码编译所在机器进行的检测

[root@Paxos libevent-2.0.21-stable]# ./configure 
checking for a BSD-compatible install... /usr/bin/install -c
...
configure: creating ./config.status
config.status: creating libevent.pc
config.status: creating libevent_openssl.pc
config.status: creating libevent_pthreads.pc
config.status: creating Makefile
config.status: creating include/Makefile
config.status: creating test/Makefile
config.status: creating sample/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
[root@Paxos libevent-2.0.21-stable]#

接着,执行 make(只给出了我们关心的库文件)

[root@Paxos libevent-2.0.21-stable]# make
...
【生成 libevent-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  .libs/event.o .libs/evthread.o .libs/buffer.o .libs/bufferevent.o .libs/bufferevent_sock.o .libs/bufferevent_filter.o .libs/bufferevent_pair.o .libs/listener.o .libs/bufferevent_ratelim.o .libs/evmap.o .libs/log.o .libs/evutil.o .libs/evutil_rand.o .libs/strlcpy.o .libs/select.o .libs/poll.o .libs/epoll.o .libs/signal.o .libs/event_tagging.o .libs/http.o .libs/evdns.o .libs/evrpc.o   -lrt  -O2   -Wl,-soname -Wl,libevent-2.0.so.5 -o .libs/libevent-2.0.so.5.1.9
【建立 libevent.so 和 libevent-2.0.so.5 到 libevent-2.0.so.5.1.9 的软链接】
libtool: link: (cd ".libs" && rm -f "libevent-2.0.so.5" && ln -s "libevent-2.0.so.5.1.9" "libevent-2.0.so.5")
libtool: link: (cd ".libs" && rm -f "libevent.so" && ln -s "libevent-2.0.so.5.1.9" "libevent.so")
【生成 libevent.a 文件】
libtool: link: ar cru .libs/libevent.a  event.o evthread.o buffer.o bufferevent.o bufferevent_sock.o bufferevent_filter.o bufferevent_pair.o listener.o bufferevent_ratelim.o evmap.o log.o evutil.o evutil_rand.o strlcpy.o select.o poll.o epoll.o signal.o event_tagging.o http.o evdns.o evrpc.o
libtool: link: ranlib .libs/libevent.a
libtool: link: ( cd ".libs" && rm -f "libevent.la" && ln -s "../libevent.la" "libevent.la" )
【生成 libevent_core-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  .libs/event.o .libs/evthread.o .libs/buffer.o .libs/bufferevent.o .libs/bufferevent_sock.o .libs/bufferevent_filter.o .libs/bufferevent_pair.o .libs/listener.o .libs/bufferevent_ratelim.o .libs/evmap.o .libs/log.o .libs/evutil.o .libs/evutil_rand.o .libs/strlcpy.o .libs/select.o .libs/poll.o .libs/epoll.o .libs/signal.o   -lrt  -O2   -Wl,-soname -Wl,libevent_core-2.0.so.5 -o .libs/libevent_core-2.0.so.5.1.9
【建立 libevent_core.so 和 libevent_core-2.0.so.5 到 libevent_core-2.0.so.5.1.9 的软链接】
libtool: link: (cd ".libs" && rm -f "libevent_core-2.0.so.5" && ln -s "libevent_core-2.0.so.5.1.9" "libevent_core-2.0.so.5")
libtool: link: (cd ".libs" && rm -f "libevent_core.so" && ln -s "libevent_core-2.0.so.5.1.9" "libevent_core.so")
【生成 libevent_core.a 文件】
libtool: link: ar cru .libs/libevent_core.a  event.o evthread.o buffer.o bufferevent.o bufferevent_sock.o bufferevent_filter.o bufferevent_pair.o listener.o bufferevent_ratelim.o evmap.o log.o evutil.o evutil_rand.o strlcpy.o select.o poll.o epoll.o signal.o
libtool: link: ranlib .libs/libevent_core.a
libtool: link: ( cd ".libs" && rm -f "libevent_core.la" && ln -s "../libevent_core.la" "libevent_core.la" )
【生成 libevent_extra-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  .libs/event_tagging.o .libs/http.o .libs/evdns.o .libs/evrpc.o   -lrt  -O2   -Wl,-soname -Wl,libevent_extra-2.0.so.5 -o .libs/libevent_extra-2.0.so.5.1.9
【建立 libevent_extra.so 和 libevent_extra-2.0.so.5 到 libevent_extra-2.0.so.5.1.9 的软链接】
libtool: link: (cd ".libs" && rm -f "libevent_extra-2.0.so.5" && ln -s "libevent_extra-2.0.so.5.1.9" "libevent_extra-2.0.so.5")
libtool: link: (cd ".libs" && rm -f "libevent_extra.so" && ln -s "libevent_extra-2.0.so.5.1.9" "libevent_extra.so")
【生成 libevent_extra.a 文件】
libtool: link: ar cru .libs/libevent_extra.a  event_tagging.o http.o evdns.o evrpc.o
libtool: link: ranlib .libs/libevent_extra.a
libtool: link: ( cd ".libs" && rm -f "libevent_extra.la" && ln -s "../libevent_extra.la" "libevent_extra.la" )
【生成 libevent_pthreads-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  .libs/evthread_pthread.o   -lrt  -O2   -Wl,-soname -Wl,libevent_pthreads-2.0.so.5 -o .libs/libevent_pthreads-2.0.so.5.1.9
【建立 libevent_pthreads.so 和 libevent_pthreads-2.0.so.5 到 libevent_pthreads-2.0.so.5.1.9 的软链接】
libtool: link: (cd ".libs" && rm -f "libevent_pthreads-2.0.so.5" && ln -s "libevent_pthreads-2.0.so.5.1.9" "libevent_pthreads-2.0.so.5")
libtool: link: (cd ".libs" && rm -f "libevent_pthreads.so" && ln -s "libevent_pthreads-2.0.so.5.1.9" "libevent_pthreads.so")
【生成 libevent_pthreads.a 文件】
libtool: link: ar cru .libs/libevent_pthreads.a  evthread_pthread.o
libtool: link: ranlib .libs/libevent_pthreads.a
libtool: link: ( cd ".libs" && rm -f "libevent_pthreads.la" && ln -s "../libevent_pthreads.la" "libevent_pthreads.la" )
【生成 libevent_openssl-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  .libs/bufferevent_openssl.o   -lssl -lcrypto -lrt  -O2   -Wl,-soname -Wl,libevent_openssl-2.0.so.5 -o .libs/libevent_openssl-2.0.so.5.1.9
【建立 libevent_openssl.so 和 libevent_openssl-2.0.so.5 到 libevent_openssl-2.0.so.5.1.9 的软链接】
libtool: link: (cd ".libs" && rm -f "libevent_openssl-2.0.so.5" && ln -s "libevent_openssl-2.0.so.5.1.9" "libevent_openssl-2.0.so.5")
libtool: link: (cd ".libs" && rm -f "libevent_openssl.so" && ln -s "libevent_openssl-2.0.so.5.1.9" "libevent_openssl.so")
【生成 libevent_openssl.a 文件】
libtool: link: ar cru .libs/libevent_openssl.a  bufferevent_openssl.o
libtool: link: ranlib .libs/libevent_openssl.a
libtool: link: ( cd ".libs" && rm -f "libevent_openssl.la" && ln -s "../libevent_openssl.la" "libevent_openssl.la" )
...
[root@Paxos libevent-2.0.21-stable]#

最后指定 make install 命令

[root@Paxos libevent-2.0.21-stable]# make install
...(将库文件安装到系统目录中)
...(变更权限和为 .a 文件增加 index)
[root@Paxos libevent-2.0.21-stable]#

此时可以看到生成的文件已经位于系统中了

[root@Paxos ~]# updatedb
[root@Paxos ~]# locate libevent
...
/usr/local/lib/libevent-2.0.so.5
/usr/local/lib/libevent-2.0.so.5.1.9
/usr/local/lib/libevent.a
/usr/local/lib/libevent.la
/usr/local/lib/libevent.so
/usr/local/lib/libevent_core-2.0.so.5
/usr/local/lib/libevent_core-2.0.so.5.1.9
/usr/local/lib/libevent_core.a
/usr/local/lib/libevent_core.la
/usr/local/lib/libevent_core.so
/usr/local/lib/libevent_extra-2.0.so.5
/usr/local/lib/libevent_extra-2.0.so.5.1.9
/usr/local/lib/libevent_extra.a
/usr/local/lib/libevent_extra.la
/usr/local/lib/libevent_extra.so
/usr/local/lib/libevent_openssl-2.0.so.5
/usr/local/lib/libevent_openssl-2.0.so.5.1.9
/usr/local/lib/libevent_openssl.a
/usr/local/lib/libevent_openssl.la
/usr/local/lib/libevent_openssl.so
/usr/local/lib/libevent_pthreads-2.0.so.5
/usr/local/lib/libevent_pthreads-2.0.so.5.1.9
/usr/local/lib/libevent_pthreads.a
/usr/local/lib/libevent_pthreads.la
/usr/local/lib/libevent_pthreads.so
/usr/local/lib/pkgconfig/libevent.pc
/usr/local/lib/pkgconfig/libevent_openssl.pc
/usr/local/lib/pkgconfig/libevent_pthreads.pc
[root@Paxos ~]#

将上面的 make 输出进行整理后,可以知道编译各个库的时候都包含了哪些内容,使用哪些选项

【生成 libevent-2.0.so.5.1.9 文件】

libtool: link: gcc -shared  -fPIC -DPIC  
.libs/event.o 
.libs/evthread.o 
.libs/buffer.o 
.libs/bufferevent.o 
.libs/bufferevent_sock.o 
.libs/bufferevent_filter.o 
.libs/bufferevent_pair.o 
.libs/listener.o 
.libs/bufferevent_ratelim.o 
.libs/evmap.o 
.libs/log.o 
.libs/evutil.o 
.libs/evutil_rand.o 
.libs/strlcpy.o 
.libs/select.o 
.libs/poll.o 
.libs/epoll.o 
.libs/signal.o 
.libs/event_tagging.o 
.libs/http.o 
.libs/evdns.o 
.libs/evrpc.o  
-lrt  -O2   -Wl,-soname -Wl,libevent-2.0.so.5 -o .libs/libevent-2.0.so.5.1.9

【生成 libevent_core-2.0.so.5.1.9 文件】

libtool: link: gcc -shared  -fPIC -DPIC  
.libs/event.o 
.libs/evthread.o 
.libs/buffer.o 
.libs/bufferevent.o 
.libs/bufferevent_sock.o 
.libs/bufferevent_filter.o 
.libs/bufferevent_pair.o 
.libs/listener.o 
.libs/bufferevent_ratelim.o 
.libs/evmap.o 
.libs/log.o 
.libs/evutil.o 
.libs/evutil_rand.o 
.libs/strlcpy.o 
.libs/select.o 
.libs/poll.o 
.libs/epoll.o 
.libs/signal.o 
-lrt  -O2   -Wl,-soname -Wl,libevent_core-2.0.so.5 -o .libs/libevent_core-2.0.so.5.1.9

【生成 libevent_extra-2.0.so.5.1.9 文件】

libtool: link: gcc -shared  -fPIC -DPIC  
.libs/event_tagging.o 
.libs/http.o 
.libs/evdns.o 
.libs/evrpc.o 
-lrt  -O2   -Wl,-soname -Wl,libevent_extra-2.0.so.5 -o .libs/libevent_extra-2.0.so.5.1.9

【生成 libevent_pthreads-2.0.so.5.1.9 文件】

libtool: link: gcc -shared  -fPIC -DPIC  
.libs/evthread_pthread.o  
-lrt  -O2   -Wl,-soname -Wl,libevent_pthreads-2.0.so.5 -o .libs/libevent_pthreads-2.0.so.5.1.9

【生成 libevent_openssl-2.0.so.5.1.9 文件】
libtool: link: gcc -shared  -fPIC -DPIC  
.libs/bufferevent_openssl.o  
-lssl -lcrypto -lrt  -O2   -Wl,-soname -Wl,libevent_openssl-2.0.so.5 -o .libs/libevent_openssl-2.0.so.5.1.9

可以看出,从库文件所包含内容上来说
libevent  = libevent_core + libevent_extra

而 libevent_pthreads 和 libevent_openssl 是两个专门用途的库。

网上有人给出如下使用建议:

  • libevent 2.0 版本之后,建议不要再直接链接 libevent 库,而应根据需要链接 libevent_core 和 libevent_extra 等库
  • libevent_core 提供了 event_base 、evbuffer 、bufferevent 、utility 等常用方法
  • libevent_extra 提供 HTTP 、DNS ,以及 RPC 等高级功能
  • 如果以多线程方式使用 libevent ,则还需要链接 libevent_pthreads 库
  • 如果用到 ssl,则需要再链接 libevent_openssl 库

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值