標籤:boost asio linux 安裝 開源
學習開源庫第一步就是編譯安裝好庫,然後運行成功一個demo,然後才能進行之後的工作。
下面就來講講boost庫在linux下的安裝。
[[email protected] ~]$ tar -zxvf boost_1_55_0.tar.gz
[[email protected] boost_1_55_0]$ ./bootstrap.sh --prefix=/home/mjf/lib
[[email protected] boost_1_55_0]$ sudo ./b2 install
1.解壓
2.產生bjam
上述命令可以帶有各種選項,具體可參考說明文檔: ./bootstrap.sh --help。其中--prefix參數,可以指定安裝路徑,如果不帶--prefix參數的話,預設路徑是 /usr/local/include 和 /usr/local/lib,分別存放標頭檔和各種庫。
3.編譯,安裝
這裡是全部編譯。當然也可以選擇只編譯一部分,選項 --with-<library> 只編譯指定的庫,如輸入--with-regex就只編譯regex庫了。
編譯完成後,進行安裝,也就是將標頭檔和產生的庫,放到指定的路徑(--prefix)下
bjam的一些常用的參數,列表如下:
| --build-dir=<builddir> |
編譯的臨時檔案會放在builddir裡(這樣比較好管理,編譯完就可以把它刪除了) |
| --stagedir=<stagedir> |
存放編譯後庫檔案的路徑,預設是stage |
| --build-type=complete |
編譯所有版本,不然只會編譯一小部分版本,確切地說是相當於: variant=release, threading=multi;link=shared|static;runtime-link=shared |
| variant=debug|release |
決定編譯什麼版本(Debug or Release?) |
| link=static|shared |
決定使用靜態庫還是動態庫 |
| threading=single|multi |
決定使用單線程還是多線程庫 |
| runtime-link=static|shared |
決定是靜態還是動態連結C/C++標準庫 |
| --with-<library> |
只編譯指定的庫,如輸入--with-regex就只編譯regex庫了 |
| --show-libraries |
顯示需要編譯的庫名稱 |
安裝完成,我們就來運行一個例子:
#include <iostream>#include <boost/timer.hpp>using namespace std;int main(){boost::timer t;cout << "max timespan:"<<t.elapsed_max()/3600<<"h"<<endl;cout << "min tmiespan:"<<t.elapsed_min()<<"s"<<endl;cout<<"now time elapsed:"<<t.elapsed()<<"s"<<endl;return 0;}
g++ -o test test.cpp -I/home/mjf/lib/include -L/home/mjf/lib/lib
./test
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
boost.asio學習筆記一、linux下boost庫的安裝