因為要用基於GCC4.8.1的boost最新版本的庫,默認apt-get install 安裝的是boost1.53, 並且基於GCC4.7.3,不是我想要的。所以決定在Ubuntu 13.04環境下載源代碼自己編譯。
下載(後面的路徑可能會變,具體參考boost網站鏈接)
wget -O boost_1_54_0.tar.bz2 http://downloads.sourceforge.net/project/boost/boost/1.54.0/boost_1_54_0.tar.bz2?r=http%3A%2F%2Fwww.boost.org%2Fusers%2Fhistory%2Fversion_1_54_0.html&ts=1375162670&use_mirror=jaist
解壓:
tar --bzip2 -xf ./boost_1_54_0.tar.bz2
開始編譯,全部編譯耗時太多,所以我僅選擇我需要的庫:
先用下面的命令查看有多少庫可以編譯:
./bootstrap.sh --show-libraries
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
The following Boost libraries have portions that require a separate build
and installation step. Any library not listed here can be used by including
the headers only.
The Boost libraries requiring separate building and installation are:
- atomic
- chrono
- context
- coroutine
- date_time
- exception
- filesystem
- graph
- graph_parallel
- iostreams
- locale
- log
- math
- mpi
- program_options
- python
- random
- regex
- serialization
- signals
- system
- test
- thread
- timer
- wave
然後就編譯我要的庫:
./bootstrap.sh --with-libraries=system,filesystem,log,thread
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86_64/b2
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...
Bootstrapping is done. To build, run:
./b2
To adjust configuration, edit 'project-config.jam'.
Further information:
- Command line help:
./b2 --help
- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html
- Boost.Build documentation:
http://www.boost.org/boost-build2/doc/html/index.html
然後運行下面的命令完成編譯。
./b2
耐心等待。不過因為不是編譯所有庫。時間會少很多。以後需要再來編譯。很快看到結果:
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/usr/src/boost_1_54_0
The following directory should be added to linker library paths:
/usr/src/boost_1_54_0/stage/lib
忘記安裝了。再運行./b2 install 命令,默認安裝在
/usr/local/lib目錄下
頭文件在
/usr/local/include/boost目錄下