(1)首先下载源码:http://softlayer-dal.dl.sourceforge.net/project/boost/boost/1.56.0/boost_1_56_0.zip
解压到某个文件夹。我解压到了D盘根文件夹:D:oost_1_56_0
(2)生成bjam.exe可运行文件
用VS2010命令行
进入到到文件夹D:oost_1_56_0。执行booststrap.bat得到:
这时在文件夹D:oost_1_56_0生成了b2.exe、bjam.exe、project-config.jam文件。
(3)用bjam.exe编译
执行命令bjam stage --without-python --toolset=msvc-10.0 --build-type=complete --stagedir="D:oost_1_56_0invc10" link=static runtime-link=shared threading=multi debug release
bjam能够參考http://blog.chinaunix.net/uid-22301538-id-3158997.html
stage表示仅仅生成库(dll和lib),用install的话还会生成包括头文件的include文件夹。
toolset指定编译器,VS2010用msvc-10.0。
without/with表示不编译/编译哪些库。
stagedir,当使用stage时用stagedir,使用install用prefix,表示编译生成文件的路径。路径的命名最好和编译器相关,编译管理。
link指定生成动态链接库或静态链接库。生成动态链接库需使用shared方式,生成静态链接库需使用static方式。
runtime-link。动态/静态链接C/C++执行时库。有shared和static两种方式,这样runtime-link和link一共能够产生4种组合方式。
threading,单/多线程编译。
debug/release。编译debug/release版本号。一般都是程序的debug版本号相应库的debug版本号。所以两个都编译。
差点儿相同须要一小时,编译完毕(中间会有警告)。
编译好后,在根目录会有个bin.v2目录,是编译过程中的暂时目录。非常大,能够手动删除。
(4)在VS中使用Boost库
新建project后须要把Boost库包括到project中。右键选择属性。在VC++文件夹的“包括文件夹”中加入Boost的根文件夹,在“库文件夹”加入刚刚编译生成的位置再加上路径lib。
之后包好头文件就可以使用,比如一个多线程的測试:
#include "boost/thread.hpp" #include "iostream" using namespace std; void threadFunc() { cout << "This is a thread function" << endl; } int main() { boost::function<void()> func(threadFunc); boost::thread t(func); t.join(); return 0; }