在Ubuntu20.04系統下使用源代碼編譯libtorrent,首先需要安裝boost,這里使用boost 1.75.0版本,在boost官網下載好原始碼壓縮包,解壓后cd到boost_1_75_0目錄下,網上查到的很多安裝方法都不適用,直接根據官網的方法安裝即可,
官網鏈接:https://www.boost.org/doc/libs/1_75_0/more/getting_started/unix-variants.html
在boost_1_75_0目錄下執行下列命令完成boost安裝:
$ ./bootstrap.sh
$ b2
$ ./b2 install --prefix=/usr/local
Boost安裝完成后,即可進行libtorrent的編譯和安裝,首先在libtorrent的GitHub官網(https://github.com/arvidn/libtorrent)上下載原始碼libtorrent-RC_2_0,需要注意,在GitHub中下載會遺漏deps目錄下兩個檔案夾中的內容,需要在GitHub中對這兩個檔案夾分別下載,再拷貝到相應目錄下,
libtorrent原始碼準備完成后,首先進行依賴包的安裝:
$ sudo apt install libboost-tools-dev libboost-dev libboost-system-dev
然后開始編譯安裝:
$ echo "using gcc ;" >>~/user-config.jam
$ b2 cxxstd=14 //注意一定要指定使用 C++ 14標準
$ sudo b2 install --prefix=/usr/local cxxstd=14
因腳本設定原因,需要將編譯完成的靜態庫libtorrent.a拷貝到/usr/local/lib目錄下,
Libtorrent的原始碼中包含有示例程式,位于原始碼檔案夾中的example目錄下,在安裝好libtorrent后可編譯該示例進行測驗,編譯方法如下:
首先更改example下的CMakeLists.txt檔案中的內容,修改內容見下面代碼的19和27行:
project(libtorrent-examples)
set(single_file_examples
simple_client
custom_storage
stats_counters
dump_torrent
dump_bdecode
make_torrent
connection_tester
upnp_test)
if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_compile_options(-Wno-implicit-int-float-conversion)
endif()
foreach(example ${single_file_examples})
add_executable(${example} "${example}.cpp")
target_link_libraries(${example} PRIVATE torrent-rasterbar torrent try_signal pthread) //增加 torrent try_signal pthread
endforeach(example)
add_executable(client_test
client_test.cpp
print.cpp
torrent_view.cpp
session_view.cpp)
target_link_libraries(client_test PRIVATE torrent-rasterbar pthread torrent try_signal) //增加 pthread torrent try_signal
然后編譯示例程式
$ mkdir build // cd至 example目錄下新建 build目錄
$ cd build //進入 build目錄下
$ cmake .. //通過 CMakeLists.txt檔案生成 Makefile檔案
$ make //執行編譯
編譯完成后會生成多個測驗用例,使用下載好的種子檔案進行測驗,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/266420.html
標籤:區塊鏈
上一篇:干貨分享:深度決議如何借助區塊鏈技術解決預付式消費困境
下一篇:資料結構之堆疊
