linux下安裝boost

linux平臺下要編譯安裝除gcc和gcc-c++以外,還須要兩個開發庫:bzip2-devel 和python-devel,所以在安裝前應該先保證這兩個庫已經安裝:
#yum install gcc gcc-c++ bzip2 bzip2-devel bzip2-libs python-devel -y

而後是去官網下載源碼包,地址
下載,解壓,按照以下步驟:
#tar xvzf boost_1_50_0.tar.gz

進入boost_1_50_0目錄:
#cd boost_1_50_0

而後是編譯安裝,boost源碼包中有配置腳本,直接用就能夠:

#sh ./bootstrap.shhtml


Building Boost.Build engine with toolset gcc... tools/build/v2/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/boost-build2/doc/html/index.html

接下來就是編譯,重點關注是否編譯成功:
#./b2

而後就是漫長的等待,若是最後出現:
The Boost C++ Libraries were successfully built!
          
The following directory should be added to compiler include paths:
          
    /home/gang/BAK/boost_1_50_0
      
The following directory should be added to linker library paths:
      
    /home/gang/BAK/boost_1_50_0/stage/lib

最後,sudo ./b2 install --prefix=/usr/local 

一、  boost中大部分庫是不用編譯成動態或者靜態連接庫。
二、  只有regex,thread等幾個庫比較麻煩一點.要編譯。
三、  若是用gcc編譯器-l指定動態連接庫的路徑,還要指定頭文件的路徑。
四、  或者連接的boost庫放到.c或.cpp以後,不然連接不能經過,編譯能夠經過。

以下所示:g++ -lz -lpthread hh.c -lboost_filesystem -lboost_threadpython

相關文章
相關標籤/搜索