boost.asio學習筆記一、linux下boost庫的安裝

來源:互聯網
上載者:User

標籤: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庫的安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.