我的系统是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版本一致