boost的编译和使用(window下)

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

REF: https://blog.csdn.net/rocklee/article/details/72885587

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值