安装,测试libtorrent

来源: http://www.lupaworld.com/?uid-25829-action-viewspace-itemid-3280

系统:ubuntu 6.10

下载libtorrent 0.1.0,解压至某个目录下,比如~/libtorrent-0.10,以下记该目录为$sourcedir。

为了编译libtorrent,需要安装boost及其开发包,尤其是libboost-serialization-dev这个包,假如不安装这个包configure可以通过,但是编译会出错。

然后
cd $sourcedir
./configure
make
make check
make install

libtorrent提供了一些examples,拿它们来测试一下,这些例子也是进一步学习libtorrent的最好范本。

下面以dump_torrent.cpp这个简单的程序为例,这个程序解析了torrent文件包含的信息。libtorrent编译后,这个程序其实已 经被作为其中的一个小组件编译了,可以在examples目录下看到dump_torrent.o文件,以及一个dump_torrent脚本。

不过,我们的目的是让dump_torrent脱离libtorrent的编译环境独立运行,就像一个单独的程序一样。

cd $sourcedir/examples
g++ dump_torrent.cpp -ltorrent -o tinfo

其中-ltorrent表示加载libtorrent的动态链接库,该库文件位于/usr/local/lib,正常情况下就会编译生成tinfo。

试着运行该程序:

./tinfo

将会得到一个错误信息:

./tinfo: error while loading shared libraries: libtorrent.so.0: cannot open shared object file: No such file or directory

用ldd可以看到,libtorrent没有找到:

ldd tinfo
    linux-gate.so.1 => (0xffffe000)
    libtorrent.so.0 => not found
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7ec4000)
    libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7e9e000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7e93000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d5f000)
    libboost_filesystem-gcc-mt-1_33_1.so.1.33.1 => /usr/lib/libboost_filesystem-gcc-mt-1_33_1.so.1.33.1 (0xb7d4d000)
    libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0xb7d3a000)
    /lib/ld-linux.so.2 (0xb7fb4000)
    librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7d31000)

把libtorrent.so所在路径加入LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=/usr/local/lib
./tinfo xxx.torrent

这样就可以看到这个torrent文件的信息了。

为了方便,可以把/usr/local/lib加入到默认的lib搜索路径中:

sudo vi /etc/ld.so.conf

加入一行:
/usr/local/lib

再运行一次ldconfig,重新读入ld.so.conf文件的信息。

至此,libtorrent的开发环境就ok了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值