1. 程式人生 > >【編譯Boost庫】Linux下如何編譯和安裝Boost庫

【編譯Boost庫】Linux下如何編譯和安裝Boost庫

前言

編譯比特幣錢包時,需要依賴Boost庫,由於編譯時間較長,在“試一試”中浪費好長時間,所以把可以成功的過程記錄下來吧。

下載Boost安裝包

  • 通過wget工具下載
wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz

反正我沒成功下載下來~

  • 手動下載安裝包
    在上述地址上下載到本地,再上傳到伺服器

解壓縮

[root@bogon software]# tar zxvf boost_1_64_0.tar.gz

編譯和安裝

先進入解壓縮後的目錄:

[root@bogon
software]# cd boost_1_64_0

然後執行bootstrap.sh指令碼並設定相關引數:

[root@bogon boost_1_64_0]# ./bootstrap.sh --with-libraries=all --with-toolset=gcc

--with-libraries指定編譯哪些boost庫all的話就是全部編譯,只想編譯部分庫的話就把庫的名稱寫上,之間用 , 號分隔即可,可指定的庫有以下幾種:

庫名 說明
    atomic
    chrono
    context
    coroutine
    date_time
    exception
    filesystem
    graph
圖元件和演算法
    graph_parallel
    iostreams
    locale
    log
    math
    mpi
用模板實現的超程式設計框架
    program_options
    python
把C++類和函式對映到Python之中
    random
    regex
正則表示式庫
    serialization
    signals
    system
    test
    thread
可移植的C++多執行緒庫
    timer
    wave

--with-toolset指定編譯時使用哪種編譯器,Linux下使用gcc即可,如果系統中安裝了多個版本的gcc,在這裡可以指定gcc的版本,比如--with-toolset=gcc-4.4

命令執行完成後看到顯示如下即為成功:

Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.6
Detecting Python root... /usr
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/build/doc/html/index.html

執行以下命令開始進行boost的編譯:

[root@bogon boost_1_64_0]# ./b2 toolset=gcc

編譯的時間大概要10多分鐘,耐心等待,結束後會有以下提示:

ln-UNIX stage/lib/libboost_wave.so
...failed updating 56 targets...
...skipped 6 targets...
...updated 1081 targets...

最後執行以下命令開始安裝boost:

[root@bogon boost_1_64_0]# ./b2 install --prefix=/usr

--prefix=/usr用來指定boost的安裝目錄,不加此引數的話預設的標頭檔案在/usr/local/include/boost目錄下,庫檔案在/usr/local/lib/目錄下。這裡把安裝目錄指定為--prefix=/usr則boost會直接安裝到系統標頭檔案目錄和庫檔案目錄下,可以省略配置環境變數。

安裝完畢後會有以下提示:

...failed updating 56 targets...
...skipped 6 targets...
...updated 13610 targets...

最後需要注意,如果安裝後想馬上使用boost庫進行編譯,還需要執行一下這個命令:

[root@bogon boost_1_64_0]# ldconfig

更新一下系統的動態連結庫。

再次編譯比特幣錢包即可。