libtorrent编译

来源:互联网 发布:mac能做什么 编辑:程序博客网 时间:2024/05/16 10:51

原文地址:http://loading.1976.blog.163.com/blog/static/127803714201152814444229/


libtorrent需要用到OpenSSL和boost库,所以应该首先准备这两个库。

1、编译OpenSSL

1.1 下载OpenSSL。我采用了1.0.0d版本,官方下载地址:http://www.openssl.org/source/openssl-1.0.0d.tar.gz
1.2 编译OpenSSL需要使用perl,在windows平台下,采用了ActivePerl。我使用了5.14.1.1402版本。官方下载地址:http://downloads.activestate.com/ActivePerl/releases/5.14.1.1401/ActivePerl-5.14.1.1401-MSWin32-x86-294969.msi
1.3 安装ActivePerl。确认其bin目录处于系统PATH变量中。
1.4 运行Vis l St io命令提示行(2010)。因为先安装了VS2010,所以命令提示行中可能没有设定perl的运行路径,需要的话,使用set PATH=%PATH%;C:\Perl\bin,设定需要的路径。
1.5 在VS命令提示行中进入到解压出来的OpenSSL目录,我们这里假设是C:\WORK\OpenSSL。
1.6 执行如下的命令

perl configure VC-WIN32
ms\do_ms
nmake -f ms\nt.mak

      上面生成了静态版本的openssl库,如果你需要动态链接库版本的,请执行nmake -f ms\ntdll.mak
1.7 编译完成以后,在C:\WORK\OpenSSL\out32中会生成所有的文件,我们需要的是libeay32.lib,ssleay32.lib,openssl.exe(如果是动态链接库版本,就还有libeay32.dll和ssleay32.dll)。

2、编译boost库

2.1 下载boost库。我采用了1.46.1版本。官方下载地址:http://sourceforge.net/projects/boost/files/boost/1.46.1/boost_1_46_1.7z/download
2.2 运行Vis l St io命令提示行(2010)。
2.3 在VS命令提示行中进入到解压出来的boost目录,我们这里假设是C:\WORK\boost。
2.4 执行如下命令
bootstrap
.\bjam link=static runtime-link=static threading=multi stage

2.5 编译完成以后,应该将C:\WORK\boost加入到需要使用boost的工程的包含目录中,相应的库文件在C:\WORK\boost\stage\lib目录中。这里我们生成了debug和release的全部静态库。可以看到,所有的库结尾都带上了s,表示是静态库,debug版本的库后面还带有gd的标志。

3、编译libtorrent

3.1 下载libtorrent。我采用了0.15.6版本。官方下载地址:http://libtorrent.googlecode.com/files/libtorrent-rasterbar-0.15.6.tar.gz。需要注意的是,libtorrent有两个团队维护版本,我用的是http://www.rasterbar.com/prod ts/libtorrent/这里的版本。
3.2 运行Vis l St io命令提示行(2010)。
3.3 在VS命令行中进入到解压出来的libtorrent目录,我们这里假设是C:\WORK\libtorrent。
3.4 将2.4步中生成的C:\WORK\boost\bjam.exe拷贝到C:\WORK\libtorrent。
3.5 设置环境变量
set BOOST_ROOT=C:\WORK\boost
set INCLUDE=%INCLUDE%;C:\WORK\OpenSSL\inc32
set LIB=%LIB%;C:\WORK\OpenSSL\out32

3.6 修改C:\WORK\boost\tools\build\v2\user-config.jam文件。在其中添加一行
using msvc : 10.0;
3.7 执行如下命令
bjam --toolset=msvc boost=source link=static runtime-link=static variant=debug character-set=unicode --without-python > builddebug.txt
bjam --toolset=msvc boost=source link=static runtime-link=static variant=release character-set=unicode --without-python > buildrelease.txt

3.8 创建C:\WORK\libtorrent\lib目录。
3.9 将C:\WORK\libtorrent\bin\msvc-10.0\debug\boost-source\link-static\runtime-link-static\threading-multi\libtorrent.lib拷贝为C:\WORK\libtorrent\lib\libtorrent-debug.lib;将C:\WORK\libtorrent\bin\msvc-10.0\release
\boost-source\link-static\runtime-link-static\threading-multi\libtorrent.lib拷贝为C:\WORK\libtorrent\lib\libtorrent-release.lib。

到目前为止,已经成功的创建了相关的所有库文件。使用时,需要添加相关目录:
头文件目录:
C:\WORK\OpenSSL\inc32
C:\WORK\boost
C:\WORK\libtorrent\include
C:\WORK\libtorrent\zlib
库文件目录:
C:\WORK\OpenSSL\out32
C:\WORK\boost\stage\lib
C:\WORK\libtorrent\lib

参考来源:
1) http://limewire.negatis.com/index.php?title=Visual_Studio_libtorrent
2) http://blog.csdn.net/Jackshen1986/archive/2010/03/23/5406426.aspx

备注:
1) 编译完成后,在使用libtorrent库时,应在工程中添加BOOST_FILESYSTEM_VERSION=2的预定义,否则会出现类似file_storage.hpp(110): error C2572: 'libtorrent::file_storage::add_file' : redefinition of default parameter : parameter 5这样的编译错误。boost的1.46版本以后,boost.filesystem缺省使用了3,必须手工指定为2,libtorrent才能正常使用。
2) 上面编译中统统示范生成的是静态链接库,在使用时,因为VS生成的工程默认的“代码生成”采用的是多线程DLL(/MDd),所以链接的时候会出现大量的LNK2005错误,解决的办法就是修改“代码生成”为多线程(/MTd),或者是自行编译出DLL版本的库来使用。

0 0
原创粉丝点击