LoginSignup
16
16

More than 5 years have passed since last update.

CentOS 6.0 gcc 4.7.2にBoost 1.5.0をインストール

Last updated at Posted at 2014-11-12

参考文献

Getting Started
Boostライブラリのビルド方

前提

~/以下にインストールする。(gcc4.7.2は~/以下の適当な場所にインストール済)

準備

まずは、ダウンロードして解凍。

$ cd ~/download
$ wget http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.gz
$ tar zxvf boost_1_50_0.tar.gz

./bootstrap.shを実行。b2, bjamを生成する。

$ cd boost_1_50_0
$ ls
INSTALL  Jamroot  LICENSE_1_0.txt  boost  boost-build.jam  boost.css  boost.png  boostcpp.jam  bootstrap.bat bootstrap.sh  doc  index.htm  index.html  libs  more  rst.css  status  tools
$ ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/v2/engine/bin.linuxx86/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

$ ls
INSTALL  LICENSE_1_0.txt  bjam   boost-build.jam  boost.png     bootstrap.bat  bootstrap.sh  index.htm   libs project-config.jam  status
Jamroot  b2               boost  boost.css        boostcpp.jam  bootstrap.log  doc           index.html  more  rst.css             tools

インストール

b2でインストール。15-20分くらいかかる。

// Build
$ ./b2 cxxflags="-std=c++11" --prefix=$HOME/oss/boost_1_50_0 -j 10 define=BOOST_SYSTEM_NO_DEPRECATED stage release
// Install
$ ./b2 install cxxflags="-std=c++0x" --prefix=$HOME/oss/boost_1_50_0

今回は~/以下にインストールするので問題ないが、忘備録。

Linuxを使っており、ディストリビューション提供のboostライブラリをインストールしている場合は、--prefixで/usr以外を必ず指定してください。
--prefixを省略した場合/usr/localが選択されますが、多くの環境では$PATHの解決順序の関係上無条件で/usr/local上のBoostが選択されてしまうでしょう。
/usr以下を使用すると環境を壊すことになりかねないので、通常は$HOME/localや$HOME/boost_1_51_0といったディレクトリを用意するのが良いでしょう。一部のディストリビューションでは$HOME/localを$PATHにデフォルトで登録しているものもあるので、複数人で共用している場合には便利です。

パスを通す。

export CPLUS_INCLUDE_PATH=$HOME/oss/boost_1_50_0/include:$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=$HOME/oss/boost_1_50_0/lib

終わり。

Tips

ビルド時に、-DBOOST_SYSTEM_NO_DEPRECATEDを付けないと、-lboost_system指定時に怒られた。
インストール時にdefine=BOOST_SYSTEM_NO_DEPRECATEDを付けてるんだけど....。深くは追ってない。

/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [bin/reader1_debug] Error 1
16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16