原文連結:boost安裝及使用的記錄
其他參考:windows下boost怎樣安裝與使用說明?
http://www.cnblogs.com/finallyliuyu/archive/2010/08/23/1806811.html
http://www.boostpro.com/download/
安裝
ubuntu:
1) 在新立得(Synaptic)裡搜尋boost安裝即可。
2) 編譯時間候需要如果使用boost的lib檔案,則需要用-l指明。
windows:
1) 事先下載 icu,假設解壓的路徑是 c:\icu。
2) 在 boost首頁下載安裝包,解壓,假設解壓的路徑是 c:\boost\。
3) 編譯或下載bjam。
4) 安裝方式有兩種,一種是install,一種是stage。stage避免把檔案拷貝一遍,推薦該方法。
A gcc
bjam stage --toolset=gcc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\gcc" release --without-graph_parallel --without-***
bjam stage --toolset=gcc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\gcc" debug --without-graph_parallel --without-***
(--without-*** 就是不要編譯的庫,比如--without-python --without-wave --without-mpi ,除此之外都編譯)
或者
bjam stage --toolset=gcc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\gcc" release --without-graph_parallel --with-***
bjam stage --toolset=gcc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\gcc" debug --without-graph_parallel --with-***
(--with-***就是僅編譯的庫,例如 --with-regex --with-filesystem)
B msvc (開啟Visual Studio 命令)
bjam stage --toolset=msvc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\vc10" release --without-***
bjam stage --toolset=msvc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\vc10" debug --without-***
或者
bjam stage --toolset=msvc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\vc10" release --with-***
bjam stage --toolset=msvc -sICU_PATH="c:\icu" --stagedir="c:\boost\bin\vc10" debug --with-***
5) 在IDE中添加boost的庫資訊
vs 2010 IDE (每個項目都需要單獨添加,很麻煩)
1.Include Path c:\boost (root dir)
2.Library Path c:\boost\bin\vc10\lib (lib dir)
3.Source Path c:\boost\boost (include-file dir)
CodeBlocks
1.Linker
Setting -> Compiler and debuger -> Global compiler setting -> Linker setting ->
Add (c:\boost \bin\gcc\*.a) (all the lib files)
2.Search
Setting -> Compiler and debuger -> Global compiler setting -> Search directories -> Compiler ->
Add (c:\boost) (root dir)
6) 如果是命令列編譯,可以改如下的bat檔案
A gcc
set boost_root=c:\boost
set boost_lib=%boost_root%\bin\gcc\lib
set use_boost=-I %boost_root% -L %boost_lib%
set filesystem=-lboost_filesystem-mgw44-mt-d-1_46_1 -lboost_system-mgw44-mt-d-1_46_1
set regex=-lboost_regex-mgw44-mt-d-1_46_1
:: example
:: g++ lex.cpp -o lex %use_boost%
:: g++ regex_1.cpp -o regex_1 %use_boost% %regex%
:: g++ traverse_dir.cpp -o traverse_dir_gcc_new %use_boost% %filesystem%
B msvc
set boost_root=c:\boost
set boost_lib=%boost_root%\bin\vc10\lib
set use_boost=/EHsc /I %boost_root% /MD /link /libpath:%boost_lib%
:: example
:: cl regex_1.cpp /Feregex_1_vc.exe %use_boost%
:: del regex_1.obj
當然,也可以寫一個makefile。