我的系統是win64的,之前裝過boost但是忘記具體的安裝過程了,看很多教程裏寫直接先運行boostrap 和 bjam 就可以了,但是我運行出來的庫在vs x64下有版本衝突:庫計算機類型與目標計算機類型x64衝突,因此想起來應該是需要在bjam的時候進行一些環境參數的配置:
bjam stage --toolset=msvc-14.0 architecture=x86 address-model=64 --without-graph --without-graph_parallel --stagedir="c:\boost\boost_1_64_0\bin\vc141-x64" link=static runtime-link=shared runtime-link=static threading=multi debug release
其中有一些參數對於64位編譯的:architecture=x86 address-model=64, 如果系統是32位的話,就將這兩個參數刪除就可以了; --toolset用於設置編譯的方式,這裏是visual studio2015, 所以是14.0, runtime_link 的賦值shared和static分別表示生成動態庫和靜態庫, debug和release分別表示生成debug版本的庫和release版本的庫; 所有生成的庫系那個會存放在--stagedir指定的路徑中;
所以具體的安裝過程如下:
1. https://www.boost.org/users/history/ 這個網址下載以往發佈的版本,最新版本可visit:https://www.boost.org/users/download/
2. 下載對應的版本後解壓,然後直接在解壓後的目錄下雙擊bootstrap批處理文件,即可生成b2.exe 和bjam.exe文件,這兩個文件都可以用於boost的安裝
3. windows下cmd進入命令行,然後進入bjam所在的目錄,64爲的話直接運行:
bjam stage --toolset=msvc-14.0 architecture=x86 address-model=64 --without-graph --without-graph_parallel --stagedir="c:\boost\boost_1_64_0\bin\vc141-x64" link=static runtime-link=shared runtime-link=static threading=multi debug release
32位,即x86的庫直接運行:
bjam stage --toolset=msvc-14.0 --without-graph --without-graph_parallel --stagedir="c:\boost\boost_1_64_0\bin\vc141-x64" link=static runtime-link=shared runtime-link=static threading=multi debug release
編譯的時間會比較久一點,結束後會生成release和debug的庫承兌出現,以filesystem這個庫爲例:
libboost_filesystem-vc140-mt-gd-1_64
libboost_filesystem-vc140-mt-1_64
有gd的表示debug版本,無gd表示release版本;mt表示多線程;
4.在Cmakelists文件中的引用,一般來講需要三個部分:
#設置包含目錄
include_directories("D:/boost_1_64_0/boost_1_64_0/")
#設置庫的鏈接目錄
link_directories("D:/boost_1_64_0/boost_1_64_0/vc141-x64/lib")
add_executable(capturevideo
capture.cpp)
target_link_libraries(capturevideo
${OpenCV_LIBS}
libboost_filesystem-vc140-mt-gd-1_64)
#target_link_libraries中添加指定的庫,注意具體名稱需要和自己的debug和release版本一致