你需要到官方網(wǎng)站下載最新的版本,最新已經(jīng)到1.47.0了
1.下載后解壓到/opt/boost_1_47_0
2.解決依賴關(guān)系 sudo apt-get install python-dev gccxml
如果還不全,就用apt-cache depends XXXXXXX查去
3.編譯bjam:
#cd /opt/boost_1_47_0 #sudo ./bootstrap.sh
編譯成功
4.編譯boost
#sudo ./bjam
開始編譯
大約要個十幾分鐘
編譯完成后:
The Boost C++ Libraries were successfully built! The following directory should be added to compiler include paths: /home/terry/Local/boost_1_47_0 The following directory should be added to linker library paths: /home/terry/Local/boost_1_47_0/stage/lib
因為我是解壓到/home/terry/Local/boost_1_46_1下了
所以編譯完了是這樣的
5.update動態(tài)鏈接庫:
sudo ldconfig
安裝完畢
三,測試使用:
1.測試代碼
#cat test.cpp #include <boost/lexical_cast.hpp> #include <iostream> int main() { using boost::lexical_cast; int a= lexical_cast<int>("123456"); double b = lexical_cast<double>("123.456"); std::cout << a << std::endl; std::cout << b << std::endl; return 0; }
2.編譯,運行
--g++ -o test test.cpp #ls test test.cpp # ./test 123456 123.456