天天看點

[libtorrent] windows搭建 libtorrent 開發環境

作業系統:win10

開發工具:VS2019

(參考文檔:libtorrent)

搭建 libtorrent 步驟:

一. 安裝 vcpkg 和 boost

1. 安裝 vcpkg 到本地

    git clone https://github.com/microsoft/vcpkg

2. 執行 bootstrap-vcpkg.bat 腳本

    .\vcpkg\bootstrap-vcpkg.bat

3. 添加vcpkg環境變量

    環境變量->PTAH->添加 vcpkg 的目錄,如下圖:

[libtorrent] windows搭建 libtorrent 開發環境

4. 安裝 boost

    .\vcpkg.exe install boost:x86-windows

    (注:此處注意,安裝需要一些時間,注意可能會因為缺少 VS英文包 報錯)

5. 安裝 OpenSSL

    (如果本地沒有安裝 SSL,那麼需要進行此步驟)

    傳送門:http://slproweb.com/products/Win32OpenSSL.html (下載下傳 32位 版本)

    安裝成功後,配置環境變量:

    環境變量->PTAH->添加 vcpkg 的目錄,如下圖:

[libtorrent] windows搭建 libtorrent 開發環境

二. 編譯 libtorrent

1. 下載下傳 libtorrent 源碼

    git clone  https://github.com/arvidn/libtorrent.git

2. git init

    git submodule update --init

3. 修改 CMakeLists.txt

    添加下邊兩行到 CMakeLists.txt 中

set(VCPKG_ROOT "D:/work/libtorrent/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE PATH "")
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT})
           

    位置如圖所示:

[libtorrent] windows搭建 libtorrent 開發環境

三. 通過 cmake-gui 生成 vs 項目

1. 下載下傳安裝 cmake-gui

    傳送門:Download | CMake

[libtorrent] windows搭建 libtorrent 開發環境

2. 配置 libcorrent

    打開 cmake-gui ,設定源碼路徑和生成路徑

[libtorrent] windows搭建 libtorrent 開發環境

    點選 configure 後,選 win32 , 自動生成配置,如下圖所示

[libtorrent] windows搭建 libtorrent 開發環境

    配置生成成功後,勾選 build_tests 和 build_examples, 點選 Generate,生成配置檔案;如下圖所示

[libtorrent] windows搭建 libtorrent 開發環境

四. 編譯 libtorrent

1. 打開VS2019 ,加載 .\libtorrent\build\ 路徑下的 libtorrent.sln, 如下圖所示:

[libtorrent] windows搭建 libtorrent 開發環境

2. 右鍵 ALL_BUILD ,全部編譯,如下圖所示:

[libtorrent] windows搭建 libtorrent 開發環境

大功告成。

繼續閱讀