Chinaunix首页 | 论坛 | 博客
  • 博客访问: 165004
  • 博文数量: 36
  • 博客积分: 1466
  • 博客等级: 上尉
  • 技术积分: 380
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-17 17:43
文章分类

全部博文(36)

分类: 系统运维

2007-06-20 06:44:00

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是什么?汗......),所以第一步就要编译它。

从把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体验下你的成果吧!

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 


 

阅读(5321) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-06-18 13:37:19

非常想和你交流一下,我的QQ836248