背景
開發環境:VS2005
boost:1.48.0
boost下載地址:http://www.boost.org/
文檔約定
BOOST_ROOT:表示boost的根目錄,本例將boost_1_48_0.7z解壓縮到F:\2-研發庫\boost\boost_1_48_0,BOOST_ROOT即表示F:\2-研發庫\boost\boost_1_48_0。
1)生成bjam.exe
運行BOOST_ROOT/bootstrap.bat,在BOOST_ROOT下生成bjam.exe
2)編譯
在BOOST_ROOT/下執行如下命名:
bjam --toolset=msvc-8.0 --with-regex stage debug threading=multi link=shared
bjam部分選項,參數說明:
--toolset=msvc-8.0|msvc-10.0,開發環境/編譯器,msvc-8.0爲vs2005,msvc-10.0爲vs2010,borland-6.0爲C++builder6.0
threading=single|multi,決定使用單線程還是多線程庫,multi爲多線程,single爲單線程
link=shared|static,連接選項,shared爲共享dll,static爲靜態庫
runtime-link=static|shared,決定是靜態還是動態鏈接C/C++標準庫
--with-<library>,只編譯指定的庫,如輸入--with-regex就只編譯regex庫
--show-libraries 顯示boost包含的庫
生成文件輸出在BOOST_ROOT/bin.v2/libs/regex/build/msvc-8.0/debug/threading-multi
//編譯filesystem
bjam --toolset=msvc-8.0 --with-filesystem stage debug threading=multi link=shared
3)使用boost的regex庫
#include <boost/regex.hpp>
boost採用自動連接技術,默認作爲靜態庫(link=static)連接,lib文件名爲:“libboost_regex-vc80-mt-gd-1_48.lib”。
若boost生成爲DLL(link=shared),則需要在工程中定義BOOST_REGEX_DYN_LINK或者BOOST_ALL_DYN_LINK宏,使工程連接動態庫,lib文件名爲:“boost_regex-vc80-mt-gd-1_48.lib”。