LoginSignup
2
2

More than 1 year has passed since last update.

任意のディレクトリにインストールしたgccを使ってBoostライブラリをビルド&インストールする方法

Last updated at Posted at 2021-05-27

はじめに

gcc 11.1.0を/opt/gcc-11.1.0にインストールして、それを使ってboost 1.76.0をビルドしようとしてはまってしまいました。その解決策を残しておきます。

  • OS : RHEL 7.9
  • gcc : 4.8.5(パッケージマネージャでインストール)、11.1.0(ソースコードからビルド)
  • python : 3.6(パッケージマネージャでインストール)

手順

まずboost 1.76.0をダウンロードして解凍します。

cd ~/Downloads
wget https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
tar zxf boost_1_76_0.tar.gz

次にb2を古い方のgcc (v4.8.5)を使ってビルドします。PATHにgcc 11.1.0へのパスを加えていないので、自動的にデフォルトのgcc 4.8.5を使ってビルドされます。ここまではBoostライブラリのビルド方法 - boostjsと同じです。

cd boost_1_76_0
./bootstrap.sh

次にboostのビルドに必要なパッケージをインストールします。

sudo yum install libicu libicu-devel python3 python3-devel

解凍したboostディレクトリ内のtools/build/example/user-config.jamをboostディレクトリ直下にコピーします。

cp tools/build/example/user-config.jam .

コピーしたuser-config.jamの最後に以下の内容を加えます。ディレクトリパスやpythonのバージョン等は適宜自分の場合に読み替えてください。

user-config.jam
# Configure gcc
using gcc : : /opt/gcc-11.1.0/bin/g++ : <cxxflags>"-I/opt/gcc-11.1.0/include -L/opt/gcc-11.1.0/lib64" <linkflags>"-Wl,-rpath -Wl,/opt/gcc-11.1.0/lib64" ;

# Configure python
using python : 3.6 : /usr/bin/python3 : /usr/include/python3.6m : /usr/lib ;

以上で準備ができたのでビルドします。/opt/boost-1.76.0にインストールするとして--prefixを設定しています。

./b2 toolset=gcc \
  --build-dir=build \
  --prefix=/opt/boost-1.76.0 \
  --user-config=user-config.jam \
  stage

エラーが出ていなければビルドが成功しているのでインストールします。

./b2 toolset=gcc \
  --build-dir=build \
  --prefix=/opt/boost-1.76.0 \
  --user-config=user-config.jam \
  install

最後に

こういうの面倒だから、本当は各自がvcpkgとかを使って自分が使うライブラリをローカルインストールしたほうがいいですね。

2
2
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
2
2