当前位置:文档之家› 编译libtorrent.lib篇

编译libtorrent.lib篇

BT的编译测试全过程为了进行libtorrent.lib的编译,首先我们需要搭建起基本的编译环境,由于libtorrent.lib 在编译时需要调用openssl里面的某些内容,所以第一步需要将openssl编译出来。

其次,我们编译libtorrent.lib的目的是为了调用它,利用其源码中的client_test.cpp的例子,来进行bt下载,而client_test.cpp在编译后链接的过程中需要调用到boost中的某些lib文件,所以在之后必须对boost编译。

注:本项目中,我们在vs2008的环境下进行编译,选用的各源程序版本如下:(1)请参考openssl编译部分,完成openssl的编译。

(2)请参考boost编译部分,完成boost的编译。

(3)进行libtorrent.lib的编译i.首先在VS2008的环境下新建一个空的lib项目(不包含预编译项),将如下目录中的相关源文件导入(方法:解决方案—源文件—右键添加现有项)。

$(SolutionDir)\libtorrent-rasterbar-0.14.4\src (导入该目录下所有的.cpp文件,不包括Makefile.in,Makefile.am文件)$(SolutionDir)\libtorrent-rasterbar-0.14.4\zlib (导入该目录下所有的.c文件)$(SolutionDir)\libtorrent-rasterbar-0.14.4\src\kademlia (导入该目录下所有的.cpp文件不包括Makefile.in,Makefile.am文件)ii.将项目中所有#include的头文件目录包含到工程中(方法:项目—属性—C\C++--常规—附加包含路径),具体有如下四个目录:$(SolutionDir)\ openssl-0.9.8a\include$(SolutionDir)\libtorrent-rasterbar-0.14.4\zlib$(SolutionDir)\libtorrent-rasterbar-0.14.4\include$(SolutionDir)\boost_1_39_0iii.为该项目添加预处理器项(项目中原本有的预处理器项WIN32、_DEBUG、_LIB不变)WIN32_LEAN_AND_MEAN_WIN32_WINNT=0x0501__USE_W32_SOCKETSTORRENT_LOGGINGTORRENT_VERBOSE_LOGGINGTORRENT_STORAGE_DEBUGTORRENT_UPNP_LOGGINGTORRENT_DISK_STATSTORRENT_STA TSTORRENT_DHT_VERBOSE_LOGGINGTORRENT_VERBOSE_BANDWIDTH_LIMITTORRENT_USE_OPENSSLUNICODE_UNICODECMAKE_INTDIR=\"Debug\"iv.编译--生成解决方案,生成成功。

生成的是debug版本的libtorrent.lib,位于(OutDir)\目录下。

附加内容:有网友提示,如果编译dll版本的话,需要添加TORRENT_BUILDING_SHARED 的预处理项,然后添加引用的lib:libboost_date_time-vc90-mt.liblibboost_filesystem-vc90-mt.liblibboost_system-vc90-mt.liblibboost_thread-vc90-mt.lib不过本人从没有进行dll版本的编译,也没有添加这里提到的四个lib文件和预处理项。

(4)到此为止,我们已经编译了openssl、boost、libtorrent.lib三项,下面我们需要利用libtorrent自带的client_test.cpp的源程序,新建控制台工程,测试libtorrent.lib的可用性。

那么我们先就进行client_test.cpp的编译。

i.在vs2008环境下,新建一个空的控制台程序,命名为client_test_ctr,并将libtorrent 源码中examp目录下的client_test.cpp程序作为源文件导入。

(方法:解决方案—源文件—右键添加现有项)。

ii. 将client_test.cpp中所有#include的头文件目录包含到工程中(方法:项目—属性—C\C++--常规—附加包含路径),具体有如下三个目录:$(SolutionDir)\libtorrent-rasterbar-0.14.4\zlib$(SolutionDir)\libtorrent-rasterbar-0.14.4\include$(SolutionDir)\boost_1_39_0iii.为该项目添加预处理器项(项目中原本有的预处理器项WIN32、_DEBUG、_ CONSOLE 不变)TORRENT_LOGGINGTORRENT_VERBOSE_LOGGINGiv.为该项目添加链接器附录库以及对应的库文件所在目录添加方法:libfilename:项目-属性—链接器—常规—附加库目录libfilepath:项目-属性—链接器—输入—附加依赖项v. 编译--生成解决方案,生成成功。

生成的是debug版本的client_test_ctr.exe程序,位于(OutDir)\目录下。

vi.测试生成的client_test_ctr.exe的可用性。

在client_test.cpp文件中,我们可以发现main(int ac,char[] av),这说明程序是在命令行模式下运行的。

具体运行命令如下:supported options:-h [ --help ] display this help message-p [ --port ] arg (=6881) set listening port-r [ --ratio ] arg (=0) set the preferred upload/download ratio.0 means infinite. Values smaller than 1are clamped to 1.-d [ --max-download-rate ] arg (=0) the maximum download rate given in kB/s.0 means infinite.-u [ --max-upload-rate ] arg (=0) the maximum upload rate given in kB/s. 0means infinite.--max-torrent-upload-rate arg (=20) the maximum upload rate for an individual torrent, given in kB/s. 0 means infinite.--max-torrent-download-rate arg (=0) the maximum download rate for an individual torrent, given in kB/s. 0 means infinite.--max-upload-slots arg (=5) the maximum number of upload slots. 0 means infinite.-s [ --save-path ] arg (=./) the path where the downloaded file/folder should be placed.-l [ --log-level ] arg (=info) sets the level at which events are logged [debug | info | warning | fatal].-f [ --log-file ] arg sets a file to log all events to-f [ --ip-filter ] arg sets the path to the ip-filter file usedto block access from certain ips.-a [ --allocation-mode ] arg (=full) sets mode used for allocating the downloaded files on disk. Possible options are[full | compact]-i [ --input-file ] arg adds an input .torrent file. At least one is required. arguments without any flag are implicitly an input file. To starta torrentless download, use <info-hash>@<tracker-url> instead of specifying a file.-m [ --monitor-dir ] arg monitors the given directory, looking for .torrent files and automatically starts downloading them. It will stop downloading torrent files that are removed fromthe directory-t [ --poll-interval ] arg (=2) if a directory is being monitored, thisis the interval (given in seconds) between two refreshes of the directory listing-w [ --wait-retry ] arg (=30) if the download of a url seed failes, this is the interval (given in seconds) towait until the next retry-o [ --half-open-limit ] arg (=-1) Sets the maximum number of simultaneoushalf-open tcp connections-b [ --bind ] arg Sets the local interface to bind outbound and the listen socket to-x [ --proxy-server ] arg Sets the http proxy to be used for tracker and web seeds connections. The stringis expected to be on the form: <hostname>:<port>. If no port is specified, 8080is assumed-n [ --proxy-login ] arg Sets the username and password used to authenticate with the http proxy. The string should be given in the form: <username>:<password>--proxy-type arg (=socks5) Sets the type of proxy to use [socks5 |http]--bind-port-start arg (=0) The lower port number that outgoing connections will be bound to--bind-port-end arg (=0) The upper port number that outgoing connections will be bound tovii.利用client_test_ctr.exe来下载文件,从命令行模式启动程序,进入到client_test_ctr.exe 所在的目录中,运行client_test_ctr.exe –i **.torrent,此后命令行界面会自动切换,进入到下载模式,在下载的过程中可以按下其他键以实现顺序下载、暂停继续、退出等功能,所有过程截图如下。

相关主题