天天看點

編譯安裝boost

 理論上,本文适用于boost的各個版本,尤其是最新版本1.48.0;适用于各種C++編譯器,如VC6.0(部分庫不支援),VS2003,VS2005,VS2008,VS2010,gcc,C++ Builder等。

1.下載下傳boost源檔案

http://www.boost.org/users/download/ 

2.安裝

cd /home/boost_1_48_0/

首先需要編譯bjam: ./bootstrap.sh --prefix=/home/boost-1.48.0/sdk/  設定庫安裝路徑

通過bjam編碼boost庫: ./bjam  install

3.設定環境變量

        在/etc/profile.d建立可執行檔案boost.sh,添加檔案内容:

#!/bin/sh
BOOST_INCLUDE=/home/boost-1.48.0/sdk/include/boost 
BOOST_LIB==/home/boost-1.48.0/sdk/lib
export BOOST_INCLUDE BOOST_LIB 
      

指令行執行:source /etc/profile.d/boost.sh

        以後在編譯程式時,隻需要用:-I$BOOST_INCLUDE -L$BOOST_LIB 即可,還要使用-l指定了連結庫。

然後, /etc/ld.so.conf 檔案添加so庫的環境變量 /home/boost-1.48.0/sdk/lib(主要關鍵問題)

修改完成後,通過ldconfig指令進行重新開機

4.遇到的問題及解決方案

安裝過程出現很多和bz及python庫相關的錯誤,解決方案如下

指令方式

sudo apt-get install libbz2-dev    yum install python-dev      
或
yum install libbz2-dev   yum install python-dev      

圖像界面方式

   點選Applications---->Add/Remove Software 去安裝這個封包件

PS 安裝過程中的錯誤:

libs/iostreams/src/bzip2.cpp:20:56: error: bzlib.h: 沒有那個檔案或目錄
libs/iostreams/src/bzip2.cpp:31: error: ‘BZ_OK’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:32: error: ‘BZ_RUN_OK’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:33: error: ‘BZ_FLUSH_OK’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:34: error: ‘BZ_FINISH_OK’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:35: error: ‘BZ_STREAM_END’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:36: error: ‘BZ_SEQUENCE_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:37: error: ‘BZ_PARAM_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:38: error: ‘BZ_MEM_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:39: error: ‘BZ_DATA_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:40: error: ‘BZ_DATA_ERROR_MAGIC’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:41: error: ‘BZ_IO_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:42: error: ‘BZ_UNEXPECTED_EOF’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:43: error: ‘BZ_OUTBUFF_FULL’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:44: error: ‘BZ_CONFIG_ERROR’ was not declared in this scope
libs/iostreams/src/bzip2.cpp:48: error: ‘BZ_FINISH’ was not declared in this scope
//mostly like above....
      

./boost/python/detail/wrap_python.hpp:50:23: error: pyconfig.h: No such file or directory

./boost/python/detail/wrap_python.hpp:75:24: error: patchlevel.h: No such file or directory

./boost/python/detail/wrap_python.hpp:78:2: error: #error Python 2.2 or higher is required for this version of Boost.Python.

./boost/python/detail/wrap_python.hpp:142:21: error: Python.h: No such file or directory

./boost/python/instance_holder.hpp:34: error: ‘PyObject’ has not been declared

./boost/python/instance_holder.hpp:41: error: expected ‘;’ before ‘(’ token

./boost/python/instance_holder.hpp:45: error: ‘PyObject’ has not been declared

./boost/python/detail/wrapper_base.hpp:21: error: expected initializer before ‘*’ token

./boost/python/detail/wrapper_base.hpp:23: error: expected initializer before ‘*’ token

./boost/python/detail/wrapper_base.hpp:30: error: expected initializer before ‘*’ token

./boost/python/detail/wrapper_base.hpp:34: error: expected initializer before ‘*’ token

./boost/python/detail/wrapper_base.hpp:43: error: ‘PyObject’ has not been declared

./boost/python/detail/wrapper_base.hpp:44: error: ISO C++ forbids declaration of ‘PyObject’ with no type

./boost/python/detail/wrapper_base.hpp:44: error: ‘PyObject’ is neither function nor member function; cannot be declared friend

windows下編譯安裝boost.

先生成bjam,要在vs附帶的指令行下執行才可以,在cmd下運作bat可能會卡主不動

bjam stage --toolset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="E:\boost_1_49" link=static runtime-link=static threading=multi debug release

預設為32位版本,編譯成64位:

bjam stage --toolset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="E:\boost_1_49_new" link=static runtime-link=static threading=multi address-model=64 debug release