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)