Ubuntu14.04安裝boost1.48
參考地址:
1. http://www.mamicode.com/info-detail-932057.html[1]
2. http://blog.csdn.net/yhrun/article/details/8099630[2]
環境: ubuntu14.04 g++4.8 boost1.48.0
1 安裝4個boost依賴庫:
apt-get install mpi-default-dev #安裝mpi庫
apt-get install libicu-dev #支持正則表達式的UNICODE字符集
apt-get install python-dev #需要python的話
apt-get install libbz2-dev #如果編譯出現錯誤:bzlib.h: No such file or directory
2 安裝boost庫
2.1 解壓壓縮包
從boost官網下載 boost_1_48_0.tar.gz (該例子將壓縮包放在Downloads中),然後解壓:
tar -xzvf boost_1_48_0.tar.gz
2.2 執行配置文件
cd boost_1_48_0
sudo ./bootstrap.sh #默認路徑爲/usr/local
在當前目錄下生成b2和bjam可執行文件(兩者一樣), 終端結果:
2.3 編譯boost庫
sudo ./b2 -a -sHAVE_ICU=1 #大約30分鐘
出現的錯誤及解決辦法:
boost_thread庫安裝失敗
錯誤1:
結果:
原因:
g++ 4.7以上的版本不能使能boost1.48及以下的版本。
解決辦法:修改 ./boost/config/stdib/libstdcpp3.hpp 文件
錯誤2:
結果:
原因:TIME_UTC定義衝突
解決辦法:將目錄 boost_1_48_0 中所有TIME_UTC 換成XTIME_UTC
locale庫安裝失敗
錯誤 :./libs/locale/src/icu/formatter.cpp中的第61行出現format函數有二義性;
原因:安裝的libicu-dev庫與原始的庫衝突
解決辦法:
sudo apt-get remove libicu-dev
成功結果:
2.4 安裝boost庫
sudo ./b2 install
2.5 設置動態庫權限
將新安裝的動態庫,設置成系統共享:
sudo ldconfig /usr/local/lib
成功結果:沒有出現 skip .. targets等非updated關鍵字
3 boost_thread 使用測試
testBoost.cpp
#include <boost/thread.hpp>
#include <iostream>
void task1() {
// do stuff
std::cout << "This is task1!" << std::endl;
}
void task2() {
// do stuff
std::cout << "This is task2!" << std::endl;
}
int main (int argc, char ** argv) {
using namespace boost;
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);
// do other stuff
thread_2.join();
thread_1.join();
return 0;
}
編譯運行g++ -o testBoost testBoost.cpp -lboost_thread
其中boost 庫需放在.c或.cpp之後,否則鏈接不能通過,編譯可以通過[1]
成功結果:
$ ./testBoost
This is task1!
This is task2!