执行bootstrap.bat,如图绿框所示:html
查看帮助能够输入:.\b2 --helpbootstrap
好比要开启多线程编译:b2 install threading=multi多线程
设置生成的是debug或者releaseide
备注:若是是使用VS2013,请指定输出库类型,不然会缺一个lib文件:工具
"没法打开文件 libboost_thread_vc120_mt_sgd-1_55.lib"。测试
在2013时,我是使用下面的语句进行编译:.net
// 若是要获取动态库:命令行
bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=shared runtime-link=shared threading=multi debug release 线程
// 若是是要获取静态库:debug
bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=static runtime-link=static threading=multi debug release
其中,注意修改--toolset=msvc-12.0,将12.0修改为对应的vs版本号,12.0是VS2013的版本号。
目标地址也要修改为你所需的。
注意,不要漏了install,它会帮你把头文件集合到一个文件夹中。
编译过程有一个复制过程,编译须要的时间比较长,本次编译过程当中,会在C盘根目录下生成一个boost文件夹,而后包含include和lib文件夹,这就是咱们将要使用的头文件和库文件。
下图三个文件分别是: 1) 将要使用的boost头文件和库文件。 2) 解压出的boost文件夹,就是使用这个文件夹来进行 1 -- 3步骤的。 3)BoostTest 测试工程。
须要简单的配置两个地方:
这里使用绝对路径,也能够配置环境来使用。
添加boost库
Boost是一个和STL相似的标准库,但它扩充了STL使得泛型的优势发挥到最佳,所以如今Boost比STL更为实用。
Step1:下载Boost库,这里我选择下载boost_1_55_0.zip
Step2:
解压boost文件到本地目录(如G:\boost_1_55_0),发现解压后的文件中有一个bootstrap.bat文件。而后以管理员身份打开cmd窗口,具体命令bootstrap.bat或者使用对应的VS工具,好比VS2012 x64 Native Tools Command Prompt工具打开cmd窗口,具体命令bootstrap.bat
,上述命令执行完毕后能够发现G:\boost_1_55_0下新生成了一个bjam.exe文件
Step3:
对于额外的一些依赖,好比boost.nowide 官网:http://cppcms.com/files/nowide/html/index.html
下载对应的Standard Version: boost_nowide.zip 包后,再合并到标准的boost文件中
Step4:
若是须要编译zlib,则须要先去http://www.zlib.net/下载对应的源码包,解压到某一路径
好比boost/otherLib/而后
命令行下设置环境变量 set ZLIB_SOURCE="D:\dyq\P\boost_1_59_0\otherLib\zlib-1.2.3"
Step5:
运行bjam.exe
Step6:
编译32位静态库:
b2 link=static runtime-link=static threading=multi debug release
编译64位静态mt库:
b2 stage --toolset=msvc-12.0 architecture=x86 address-model=64 --stagedir=".\stage\vc12_x64" link=static runtime-link=static threading=multi debug release
b2 stage --toolset=msvc-12.0 architecture=x86 address-model=64 --stagedir=".\stage\vc12_x64" link=static runtime-link=shared threading=multi debug release
编译64位静态md库:
b2 stage --toolset=msvc-12.0 architecture=x86 address-model=64 --stagedir=".\stage\vc12_x64" link=static runtime-link=shared threading=multi debug release
Step7:
添加boostest工程的包含目录和库目录
包含目录添加 G:\boost_1_55_0
库目录添加 G:\boost_1_55_0\stage\lib
注意:程序的运行时(多线程/多线程DLL)要与库保持一致,不然连接会报找不到文件的错误