Boost编译
1,编译Boost.Build Engine ,生成b2.exe
#进入解压根目录
cd boost_1_55_0
bootstrap
编译完成生成b2.exe
2,编译boost库
b2 --stagedir="D:\Builds\Boost\boost_1_55_0\lib\vc10" link=static runtime-link=shared threading=multi debug release --build-dir="D:\Builds\Boost\boost_1_55_0\build" msvc stage
b2和bjam是相同的,具体参数可以使用b2 –help查看。可指定参数只编译指定库。
3,生成的boost库名称解析
BOOST_LIB_PREFIX + BOOST_LIB_NAME + "-" + BOOST_LIB_TOOLSET + "-" + BOOST_LIB_THREAD_OPT + "-" + BOOST_LIB_RT_OPT + "-" + BOOST_LIB_VERSION
- 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形式.
4,link和runtime-link组合分析
Link和Runtime-link的作用
(1)Link
生成动态/静态链接库,动态链接库使用shared,静态链接库使用static。一般boost库|都可以用static方式编译,最终发布程序带着boost的dll比较累赘。
(2)Runtime-link
动态/静态链接C/C++运行时库,也有static和shared两种。runtime-link和link总共可以产生4中组合方式。
组合结果
序号 | link | runtime-link | 生成库后缀 | 备注 |
---|---|---|---|---|
1 | static | static | libboost_date_time-vc120-mt-sgd-1_56.lib,libboost_date_time-vc120-mt-s-1_56.lib | |
2 | static | shared | libboost_date_time-vc120-mt-gd-1_56.lib,libboost_date_time-vc120-mt-1_56.lib | |
3 | shared | static | 无法编译 | |
4 | shared | shared | boost_date_time-vc120-mt-gd-1_56.dll(lib),boost_date_time-vc120-mt-1_56.dll(lib) | |
5 | 缺省 | 缺省 | 同2 | |
6 | –build-type=complete | 以上所有 |
MongoDB编译
1,环境准备
- 下载并编译Boost(>=1.49)
-
Python(2.x)
安装Python,并将Python/Script加到path路径。
-
Scons
安装依赖Python环境。
-
Git
下载源码:git clone -b legacy https://github.com/mongodb/mongo-cxx-driver.git
2,编译mongodb驱动
全版本编译:
-- 静态链接 生成libmongoclient-s.lib (Relesae)
scons -- --prefix=<install-path> --cpppath=<path-to-boost-headers> --libpath=<path-to-boost-libs> install --dynamic-boost=off
-- 静态链接 生成libmongoclient-sgd.lib (Debug)
scons -- --prefix=<install-path> --cpppath=<path-to-boost-headers> --libpath=<path-to-boost-libs> install --dbg=on --dynamic-boost=off
-- 动态链接 生成libmongoclient.lib(runtime dynamic,link static)和mongoclient.lib,mongoclient.dll(Release)
scons -- --prefix=<install-path> --cpppath=<path-to-boost-headers> --libpath=<path-to-boost-libs> install --dynamic-windows --sharedclient --dynamic-boost=off
-- 动态链接 Debug
scons -- --prefix=<install-path> --cpppath=<path-to-boost-headers> --libpath=<path-to-boost-libs> install --dynamic-windows --sharedclient --dbg=on
Remark : windows系统上路径要使用反斜线或者双斜线。使用runtime dynamic ,link static 的方式编译链接可以通过,但是运行时出现意料之外的结果。auth校验无法通过。
-- runtime dynamic ,link static
libmongoclient.lib
libmongoclient-gd.lib
-- runtime static ,link static
libmongoclient-s.lib
libmongoclient-sgd.lib
-- runtime dynamic ,link static
mongoclient.dll
mongoclient.exp
mongoclient.lib
mongoclient.pdb
mongoclient-gd.dll
mongoclient-gd.exp
mongoclient-gd.lib
mongoclient-gd.pdb
3,静态链接mongodb
预编译头使用
STATIC_LIBMONGOCLIENT