- 论坛徽章:
- 0
|
libtorrent在linux下的编译笔记
作者:writer15 mail:writer15(at)163.com
转载请注明原作者名称,联系方法和出处
前言
E文好的朋友不要花时间在这文章上了,直接去看libtorrent 0.10的manual吧(0.12中的manual没有安装说明,怪得很!),它说得很清楚!
经过好几天的研究,终于找到比较简单的方法编译libtorrent。
其间走了不少弯路呀,其实libtoreent manual就写得很清楚,只能怪自己E文不好,看了后还是弄不懂……唉~~~没办法谁叫自己连去考4级的资格都没呢?悔不当初,哈哈。
平台环境
vmware下的fc4, boost 1.33.1, gcc 4.0.0, libtorrent 0.12
编译boost
因为libtorrent使用了boost库(你不知道boost是什么?汗......),所以第一步就要编译它。
从
http://sourceforge.net/project/showfiles.php?group_id=7586
把boost 1.33.1的源代码包下载回来, 放到~/目录下, 并解压
[writer@localhost ~]$ tar zxvf boost_1_33_1.tar.gz
因为编译boost和libtorrent都要用到一个叫bjam的工具, 所以要先编译它(够烦的......)
进行bjam源代码的目录, 并运行编译脚本
[writer@localhost ~]$ cd boost_1_33_1/tools/build/jam_src/
[writer@localhost jam_src]$ ./build.sh
生成的可执行文件bjam保存在bin.linuxx86目录下, 将它复制到/bin以方便调用
[writer@localhost jam_src]$ cp bin.linuxx86/bjam /bin
接下来可以编译boost了^o^, 先擦一把汗 -o-
输入如下命令进行编译boost,但不安装
[writer@localhost jam_src]$cd ~/boost_1_33_1
[writer@localhost boost_1_33_1]$ bjam stage
之所以不安装的boost是因为编译libtorrent不需要,而且安装后很可能和系统原来的boost库引起混乱。(如果你确定要安装, 请参考
http://blog.csdn.net/goodboy1881/archive/2006/03/27/640004.aspx
)
现在你可以去喝杯荼或者打几盘KOF再回来了 -o-
完成编译后所有的库文件都保存在~/boost_1_33_1/stage目录下,而头文件就在~/boost_1_33_1/boost/目录下
编译libtorrent
输入下面的命令,告诉bjam哪里可以找到boost-build(boost-build是什么?我也说不清,反正这样做就能编译libtorrent -o-)
[writer@localhost boost_1_33_1]$ export BOOST_BUILD_PATH=~/boost_1_33_1/tools/build/v2
还要在~/boost_1_33_1/tools/build/v2/user-config.jam文件添加这么一行
using gcc ;
还要告诉bjam哪里可以找到boost库和头文件
[writer@localhost boost_1_33_1]$ export BOOST_ROOT=~/boost_1_33_1
把下载回来libtorrent-0.12.tar.gz放到~/目录并解压,进入它的目录并编译
[writer@localhost boost_1_33_1]$ cd ~
[writer@localhost boost_1_33_1]$ tar zxvf libtorrent-0.12.tar.gz
[writer@localhost boost_1_33_1]$ cd ~/libtorrent-0.12/
[writer@localhost libtorrent-0.12]$ bjam
默认是编译成debug版的动态库的,可以加上release参数编译成release,或者加上link=static编译成静态库!
[writer@localhost libtorrent-0.12]$ bjam link=static release
libtorrent的源代码目录下面还有example和test目录,要编译他们进入他们的目录调用bjam即可!
[writer@localhost ~]$ cd ~/libtorrent-0.12/example/
[writer@localhost ~]$ bjam
[writer@localhost ~]$ cd ~/libtorrent-0.12/test/
[writer@localhost ~]$ bjam
编译出来的.o和可执行文件都保存在相应的bin目录下面相应的目录下,比如
~/libtorrent-0.12/bin/gcc/debug/dht-support-on/link-static/logging-none/threading-multi
~/libtorrent-0.12/bin/gcc/release/dht-support-on/link-static/logging-none/threading-multi
~/libtorrent-0.12/examples/bin/gcc/debug/dht-support-on/link-static/logging-none/threading-multi
~/libtorrent-0.12/examples/bin/gcc/release/dht-support-on/link-static/logging-none/threading-multi
还等什么,赶快到example目录下运行client_test体验下你的成果吧!
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36381/showart_324814.html |
|