libtorrent编译

windos上编译libtorrent

一.源码下载地址

https://github.com/arvidn/libtorrent/releases

二.编译过程碰到的问题

注意,本人编译的库是64位的。编译这个库是想在QT上使用。
编译官方示例:
https://www.libtorrent.org/building.html
文中有多种编译方法,我试过好几种,都会遇到问题,下面介绍我使用过的两种编译方式

使用cmake

参考 https://www.libtorrent.org/building.html#building-with-cmake
我编译的时候加上了build_examples选项,编译完之后将库放在example文件夹下,exe文件可以正常运行
问题:我编译出来的库文件很小,当我想在其他项目中使用库文件时,会报函数找不到的错误。我个人感觉是这种方式编译的库不全,具体我也没有弄明白,如有大神可留言指正。

使用boost编译
依赖库编译

1.编译zlib(本人项目需要),大家自行百度即可,我没碰到什么问题,可不安装
2.openssl
我直接从官方下载的安装包,直接安装的
https://slproweb.com/products/Win32OpenSSL.html
注意:light版是精简版,libtorrent调用可能会报函数找不到的错误,建议安装正常版,我安装的1.1.1版本
3.boost
编译的时候要用编译器自带的指令框,比如我用的是vs2019
在这里插入图片描述
打开指令框,切换到boost的下载目录,运行:

bootstrap.bat 

我直接执行b2,会报 模块计算机类型“x64”与目标计算机类型“x86”冲突。下面的指令也是网上找的,address-model就是计算机位数,-j 4是4线程编译,数字越大编译会越快,但是要考虑计算机性能。toolset=msvc-14.2根据自己的版本进行修改,怎么查看msvc版本我放到下面了。

b2 -q --with-system --with-date_time --toolset=msvc-14.2 address-model=64 variant=release link=static runtime-link=static cxxflags="-O1 -Gy -Gw -GL" linkflags="/NOLOGO /DYNAMICBASE /NXCOMPAT /LTCG /OPT:REF /OPT:ICF=5 /MANIFEST:EMBED /INCREMENTAL:NO" --hash -j 4
libtorrent编译

1.将boost下生成的b2.exe复制到libtorrent下载目录下,我下载的是1.2.19版本
在这里插入图片描述
2.
指令框切换到libtorrent下载路径,执行:

b2 -q --without-python --toolset=msvc-14.2 address-model=64 variant=release link=static runtime-link=static debug-symbols=on encryption=on crypto=openssl openssl-version=1.1 logging=off dht=on windows-version=win10 boost-link=static -sBOOST_ROOT="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0" include="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0" include="D:\WorkSoftware\library\openssl\include" library-path="D:\WorkSoftware\library\openssl\lib" library-path="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0\stage\lib" --prefix="D:\WorkSoftware\library\QBITTORRENT\libtorrent-1.2.19\build_b" cxxflags="-O1 -Gy -Gw -GL" define=BOOST_ASIO_DISABLE_CONNECTEX linkflags="/NOLOGO /DYNAMICBASE /NXCOMPAT /LTCG /OPT:REF /OPT:ICF=5 /MANIFEST:EMBED /INCREMENTAL:NO" --hash -j 4

再执行

b2 -q --without-python --toolset=msvc-14.2 address-model=64 variant=release link=static runtime-link=static debug-symbols=on encryption=on crypto=openssl openssl-version=1.1 logging=off dht=on windows-version=win10 boost-link=static -sBOOST_ROOT="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0" include="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0" include="D:\WorkSoftware\library\openssl\include" library-path="D:\WorkSoftware\library\openssl\lib" library-path="D:\WorkSoftware\library\QBITTORRENT\boost_1_81_0\stage\lib" --prefix="D:\WorkSoftware\library\QBITTORRENT\libtorrent-1.2.19\build_b" cxxflags="-O1 -Gy -Gw -GL" define=BOOST_ASIO_DISABLE_CONNECTEX linkflags="/NOLOGO /DYNAMICBASE /NXCOMPAT /LTCG /OPT:REF /OPT:ICF=5 /MANIFEST:EMBED /INCREMENTAL:NO" --hash -j 4 install

编译完就会在prefix设定的目录下生成库文件了。

三.MSVC版本查看

vs运行如下代码,会有一个数字:

    int num = _MSC_VER; // get the version
    cout << "My MSVC version is: " << num << endl;

如图
在这里插入图片描述
对应表:
10.0 1600 (Visual Studio 2010 10.0)
11.0 1700 (Visual Studio 2012 11.0)
12.0 1800 (Visual Studio 2013 12.0)
14.0 1900 (Visual Studio 2015 14.0)
14.1 1910 (Visual Studio 2017 15.0)
14.11 1911 (Visual Studio 2017 15.3)
14.12 1912 (Visual Studio 2017 15.5)
14.13 1913 (Visual Studio 2017 version 15.6)
14.14 1914 (Visual Studio 2017 version 15.7)
14.15 1915 (Visual Studio 2017 version 15.8)
14.16 1916 (Visual Studio 2017 version 15.9)
14.20 1920 (Visual Studio 2019 Version 16.0)
14.21 1921 (Visual Studio 2019 Version 16.1)
14.22 1922 (Visual Studio 2019 Version 16.2)
14.23 1923 (Visual Studio 2019 Version 16.3)
14.24 1924 (Visual Studio 2019 Version 16.4)
14.25 1925 (Visual Studio 2019 Version 16.5)
14.26 1926 (Visual Studio 2019 Version 16.6)
14.27 1927 (Visual Studio 2019 Version 16.7)
14.28 1928 (Visual Studio 2019 Version 16.8 + 16.9)
14.29 1929 (Visual Studio 2019 Version 16.10 + 16.11)
14.30 1930 (Visual Studio 2022 Version 17.0)
14.31 1931 (Visual Studio 2022 Version 17.1)
14.32 1932 (Visual Studio 2022 Version 17.2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 libtorrent4j 下载种子,您需要进行以下操作: 1. 导入 libtorrent4j 库和相关的模块,例如: ```java import com.frostwire.jlibtorrent.*; ``` 2. 创建一个 `SessionManager` 对象,并设置一些参数,例如: ```java SettingsPack settings = new SettingsPack(); settings.setInteger(SettingsPack.int_types.download_rate_limit.swigValue(), 1000); settings.setInteger(SettingsPack.int_types.upload_rate_limit.swigValue(), 1000); SessionManager s = new SessionManager(); s.applySettings(settings); s.start(); ``` 在这个例子中,我们设置了最大下载速度和上传速度为 1000 B/s,并创建了一个 `SessionManager` 对象。然后,我们使用 `applySettings` 方法将设置应用于会话管理器,并使用 `start` 方法启动会话管理器。 3. 创建一个 `TorrentHandle` 对象,并通过 `addTorrentInfo` 方法将种子添加到会话管理器中,例如: ```java String torrentFilePath = "/path/to/torrent/file"; byte[] torrentFileBytes = Files.readAllBytes(Paths.get(torrentFilePath)); TorrentInfo torrentInfo = new TorrentInfo(torrentFileBytes); TorrentHandle torrentHandle = s.getTorrents().addTorrentInfo(torrentInfo); ``` 在这个例子中,我们将种子文件读入 `byte` 数组中,并使用 `TorrentInfo` 对象解析种子文件的元数据。然后,我们使用 `addTorrentInfo` 方法将元数据添加到会话管理器中,并获得一个 `TorrentHandle` 对象,用于管理下载进程。 4. 启动下载进程,例如: ```java torrentHandle.resume(); ``` 在这个例子中,我们使用 `resume` 方法启动下载进程。 5. 等待下载完成,并关闭会话管理器,例如: ```java while (!torrentHandle.isFinished()) { System.out.println("Downloaded: " + torrentHandle.getStatus().getProgress() * 100 + "%"); Thread.sleep(1000); } s.stop(); ``` 在这个例子中,我们使用 `isFinished` 方法检查下载进程是否完成,如果没有完成,则打印下载进度,并使用 `Thread.sleep` 方法暂停 1 秒钟。一旦下载完成,我们使用 `stop` 方法关闭会话管理器。 这就是使用 libtorrent4j 下载种子的基本步骤。请注意,这只是一个简单的例子,您可能需要根据具体情况进行更多的设置和调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值