注:本文为工作问题记录,有些还未搞清楚原理,请见谅。
借鉴了网上分享的资料,感谢。
错误 LNK1104 无法打开文件“libboost_filesystem-vc140-mt-1_58.lib”
boost库是如何知道程序中所需要的lib版本的?
boost/config/auto_link.hpp 里包含以下:
# pragma comment(lib, BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT "-" BOOST_LIB_VERSION ".lib")
... ...
// vc10:
# define BOOST_LIB_TOOLSET "vc100"
# elif defined(BOOST_MSVC) && (BOOST_MSVC < 1800)
// vc11:
# define BOOST_LIB_TOOLSET "vc110"
# elif defined(BOOST_MSVC) && (BOOST_MSVC < 1900)
// vc12:
# define BOOST_LIB_TOOLSET "vc120"
# elif defined(BOOST_MSVC)
// vc14:
# define BOOST_LIB_TOOLSET "vc140"
boost版本,编译器版本,链接类型(静态/动态),是否调试等信息。都是用宏去选择的。
Visual Studio 6 : vc6
Visual Studio 2003 : vc7
Visual Studio 2005 : vc8
Visual Studio 2008 : vc9
Visual Studio 2010 : vc10
Visual Studio 2012 : vc11
Visual Studio 2013 : vc12
Visual Studio 2015 : vc14
BOOST_LIB_PREFIX: 静态库为 "lib" (否则无,是用动态链接库)
BOOST_LIB_NAME: 库的基本名称 ( 比方说 boost_regex).
BOOST_LIB_TOOLSET: 编译工具集名称 ( 比如:vc6, vc7, bcb5 )
BOOST_LIB_THREAD_OPT: 多线程为 "-mt" ,否则为空
BOOST_LIB_RT_OPT: 指示使用的运行库的后缀,
组合下面的一个或者更多字符:
s 静态运行库,指的是静态链接到运行时库(不出现表示动态).
g 调试/诊断 runtime (release if not present).
d 调试版本 (不出现表示 release 版 ).
p STLPort 版本.
注:对 vc 来说,gd 总是一起出现
BOOST_LIB_VERSION: Boost 版本, Boost 版本 x.y 表示为 x_y形式.
编译:为了简化boost库的编译,boost库中带了一个用来编译的工具,名字是bjam.exe或者b2.exe.
1:运行boost下的bootstap.bat脚本就会自动生上述的两个编译工具,并且拷贝到boost目录下. 也可以进入tools/build目录下找到类似的脚本或者项目源码来编译.
2: bjam.exe的参数
Feature
|
Allowed values
|
Notes
|
variant
|
debug,release
|
|
link
|
shared,static
|
Determines if Boost.Build creates shared or static libraries
|
threading
|
single,multi
|
Cause the produced binaries to be thread-safe. This requires proper support in the source code itself.
|
address-model
|
32,64
|
Explicitly request either 32-bit or 64-bit code generation. This typically requires that your compiler is appropriately configured. Please refer to
the section called “C++ Compilers”
and your compiler documentation in case of problems.
|
toolset
|
(Depends on configuration)
|
The C++ compiler to use. See
the section called “C++ Compilers”
for a detailed list.
(Vs2008)msvc-8.0 (vs2010)msvc-10.0
|
include
|
(Arbitrary string)
|
Additional include paths for C and C++ compilers.
|
define
|
(Arbitrary string)
|
Additional macro definitions for C and C++ compilers. The string should be either SYMBOL or SYMBOL=VALUE
|
cxxflags
|
(Arbitrary string)
|
Custom options to pass to the C++ compiler.
|
cflags
|
(Arbitrary string)
|
Custom options to pass to the C compiler.
|
linkflags
|
(Arbitrary string)
|
Custom options to pass to the C++ linker.
|
runtime-link
|
shared,static
|
Determines if shared or static version of C and C++ runtimes should be used.
|
--build-dir=
<builddir>
|
编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了)
|
--stagedir=
<stagedir>
|
存放编译后库文件的路径,默认是stage
|
--build-type=
complete
|
编译所有版本,不然只会编译一小部分版本(确切地说是相当于:variant=release, threading=multi;link=shared|static;runtime-link=shared)
|
variant=
debug|release
|
决定编译什么版本(对应文件中的d 调试版本 不出现表示 release 版)
|
link=
static|shared
|
决定使用静态库还是动态库。(对应文件中的BOOST_LIB_PREFIX )
|
threading=
single|multi
|
决定使用单线程还是多线程库。(对应文件中的BOOST_LIB_THREAD_OPT)
|
runtime-link=
static|shared
|
决定是静态还是动态链接C/C++标准库。(对应文件中的BOOST_LIB_THREAD_OPT)
|
--with-
<library>
|
只编译指定的库,如输入--with-regex就只编译regex库了。
|
--show-
libraries
|
显示需要编译的库名称
|
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=static link=static stage
意思是要生静态库,该静态库静态链接C运行时库
生成的文件名字是:libboost_date_time-vc100-mt-sgd-1_48.lib(debug version),libboost_date_time-vc100-mt-s-1_48.lib(release version) 两个文件.
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=shared link=static stage
意思是要生静态库,该静态库动态链接C运行时库
生成的文件名字是:libboost_date_time-vc100-mt-gd-1_48.lib(debug verion),libboost_date_time-vc100-mt-1_48.lib(release version) 两个文件.
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=shared link=shared stage
意思是要生动态库,该动态库动态链接C运行时库
生成的文件名字是:boost_date_time-vc100-mt-gd-1_48.lib(debug version),boost_date_time-vc100-mt-1_48.lib(release version) 两个文件.
生成的dll名字是:boost_date_time-vc100-mt-gd-1_48.dll(debug version),boost_date_time-vc100-mt-1_48.dll(release version)
编译选项方面还有install等参数.
boost库编译流程
http://www.boost.org 下载最新版本 boost_1_67_0
vs2017 编译 boost_1_67_0 流程
1 启动命令行
![](https://i-blog.csdnimg.cn/blog_migrate/5607d0f375ed581dca9586aba658fb25.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1726dd4866ece115afe9fbf480b574bd.png)
2 进入源代码目录
d:\Program Files (x86)\Microsoft Visual Studio\2017\Community>F:
F:\>cd code
F:\code>cd boost_1_67_0
F:\code\boost_1_67_0>
3 建立编译工具bjam.exe----需要执行bootstrap.bat
成功后,会在boost根目录下生成b2.exe、bjam.exe、project-config.jam、bootstrap.log四个文件。其中b2.exe和bjam.exe两个作用一样,bjam.exe对应的是老版本,b2是bjam的升级版本。
![](https://i-blog.csdnimg.cn/blog_migrate/0fb439b02c0c4d0cde8605f1fa082502.png)
F:\code\boost_1_67_0>bootstrap.bat
Building Boost.Build engine
此时不应有 \Microsoft。
方案 1 :网上找的
(使用后 未解决)
看环境变量中是不是有填错的地方。比方末尾多写了一个反斜杠“/”,还是当中的变量加了双引号。
在【我的电脑】->【属性】->【高级系统设置】->【环境变量】,系统变量里PATH变量的值。
经检查以下含有双引号
"D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\Hostx86\x86;";
配置完后,重启命令框
方案 2: 跳转到目录里,点击运行命令工具,执行脚本
(使用后 解决)
![](https://i-blog.csdnimg.cn/blog_migrate/cff2dd79542af48c5172b5b4a5d350b5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b316c2f19a02453ce86b4f3b67fc83b1.png)
4 指定编译命令
使用
bjam 编译报错
bjam stage --toolset=msvc-14.0 --without-graph --without-graph_parallel --stagedir=
"F:\code\boost_1_67_0\bin\vc14"
link=
static
runtime-link=shared runtime-link=
static
threading=multi debug release
![](https://i-blog.csdnimg.cn/blog_migrate/2c8f190eddbc74e5f37d35a543319e65.png)
使用b2 编译成功
b2 address-model=64 architecture=x86
![](https://i-blog.csdnimg.cn/blog_migrate/b0313c460ec8cfc34490a7d8da72a7ef.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0c54a9847f553837b358791a4d8495d0.png)
编译参数介绍
bjam
address-model
=64
--toolset
=msvc-14.0
link
=shared
runtime-link
=shared
runtime-link
=static
threading
=multi
address-model
: 如果没有这个参数,是生成32位的平台库,=x64是生成x64的平台库
–toolset=msvc-14.0
: 编译器,比如msvc-14.0(VS2015),可选的还有gcc, borland等
link
:生成动态链接库(=static)/静态链接库(=shared)
runtime-link
:动态/静态链接C++运行库,有shared和static两种方式
threading=multi
:单/多线程编译,一般写多线程,直接指定为multi
编译的过程会比较长,最后会在boost目录下面生成两个文件夹
- stage:对应的lib和dll文件
- bin.v2:编译时的中间文件,可以直接删除掉