Boost 庫編譯過程複雜,本文提供針對 Borland 編譯器的完整步驟,含 Debug/Release/完整三種建置模式。
boost_1_36_0.7z (源碼, ~25MB, 解壓後 ~175MB)boost-jam-3.1.16-1-ntx86.zip (含 bjam.exe)X:\tmp\boost_1_36_0 (需 2GB+ 可用空間)bjam.exe 複製至源碼根目錄E:\boost_1_36_0bjam --show-libraries
bjam install --toolset=borland --prefix="E:\boost_1_36_0" debug
--without-wave --without-mpi --without-python --without-math --without-graph
關鍵參數:--toolset=borland 指定編譯器,debug 產生帶 -d- 的除錯庫。
bjam install --toolset=borland --prefix="E:\boost_1_36_0" release
--without-wave --without-mpi --without-python --without-math --without-graph
bjam install --toolset=borland --prefix="E:\boost_1_36_0" --build-type=complete
耗時 ~1小時,產生 -s- (靜態執行階段) 庫檔。
E:\boost_1_36_0\
├── include\boost-1_36\ # 頭文件
└── lib\ # 庫文件
├── *.dll # 動態連結庫
├── *1_36.lib # 導入庫
├── *.lib # 靜態庫
├── *-d-* # Debug 版
├── *-mt-* # 多執行緒版
└── *-sg-* # 單執行緒版 (完整建置才有)
E:\boost_1_36_0\include\boost-1_36E:\boost_1_36_0\lib#include <vcl.h>
#pragma hdrstop
#include <boost/regex.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender) {
boost::regex reg("(.*)");
bool b = boost::regex_match("I love C++Builder.", reg);
if (b) ShowMessage("Boost 安裝成功!");
}
分別在 Debug/Release 組態下編譯執行驗證。
-d- 庫 → 未建置 Debug 版-s- 庫 → 未完整建置 (--build-type=complete)-- 雙減號、= 前後無空格、路徑用雙引號