下载Boost源代码与安装VS
博主使用的是版本boost_1_61_0、vs2008或者vs2010
1.解压boost文件,使用编译器的命令行进入解压后的根目录
2.敲入命令.\bootstrap.bat (on Windows)或者./bootstrap.sh (on other operating systems)
3.执行./b2 install --prefix=PREFIX
PREFIX就是你要安装的目录位置,Win32默认在 C:\Boost;Unix默认在 /usr/local on Unix. Linux
4.可选的。可以将PREFIX/bin设置为环境变量方便使用
下面就是开始boost的hello之旅了
http://blog.csdn.net/xinqingwuji/article/details/51737177
博主使用的命令:b2 stage --toolset=msvc-9.0 variant=debug link=shared threading=multi runtime-link=shared
20170420补充
使用动态库链接还是乖乖的,运行时还需要一堆动态库,后来还是从了静态库。。。。
修改为b2 install --toolset=msvc-10.0 variant=debug link=static threading=multi runtime-link=shared
仅供参看,使用都是动态链接
详细解释:
第二步执行后在boost根目录(也是bootstrap.bat的目录)下会生成b2.exe、bjam.exe、project-config.jam、bootstrap.log四个文件。
第三步执行的是默认安装。可以键入b2 --help来查看编译的配置情况。
博主参考的配置参数:
b2 stage/install
重要参数说明:
[install|stage]:
stage:只在stage目录下放置编译的库文件,可以由--stagedir=<STAGEDIR>选项来指定目录。默认是根目录stage目录下。
install:会生成一些boost的头文件目录include文件,直接使用。
toolset:
win32下的版本msvc-6.0 : VC6.0 msvc-7.0: VS2003 msvc-8.0: VS2005 msvc-9.0: VS2008 msvc-10.0: VS2010
--with-<library>:指定编译的库
--without-<library>:指定不编译的库。默认是全编译的
--show-libraries:显示需要编译的全部库文件
variant=debug|release 编译的版本debug或者release
link=static|shared 静态或者动态编译库
threading=single|multi 单线程或者多线程。一般当然还是多线程环境多。
runtime-link=static|shared 静态链接或者动态链接C/C++运行库
--build-type=<type>:
complete 编译所有可能的变量,相当于variant=release,threading=multi;link=shared|static;runtime-link=shared
Boost库命名特点:
1.包含boost单词
2.link=static,生成的库lib开头,然后再接boost
3.threading=mult,生成的库加入关键词-mt
4.variant=debug,生成的库加入关键词-gd
5.runtime-link=static,生成的库加入关键词-s
Feature | Allowed values | Notes |
---|---|---|
variant | debug,release | |
link | shared,static | Determines if B2 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. |
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 |
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. |