1、gccのインストール依存関係の設定

1.1 必要なソフトウェアのインストール

#yum install -y gcc gcc-c++ gmp-devel bzip2

1.2 gccパッケージをダウンロードし、解凍する。

#wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-11.2.0/gcc-11.2.0.tar.gz
# tar -xvf gcc-11.2.0.tar.gz

1.3 コンフィギュレーションの依存関係

./contrib/download_prerequisites
#cd gcc-11.2.0

ダウンロードに成功すると、次のようなプロンプトが表示されます。All prerequisites downloaded successfully.

ダウンロードに失敗した場合は、依存関係を手動でインストールできます。 ダウンロードする依存パッケージを以下に示す:

  • gmp-6.1.0.tar.bz2
  • mpfr-3.1.6.tar.bz2
  • mpc-1.0.3.tar.gz
  • isl-0.18.tar.bz2

ダウンロードURL: https://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2 https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.6.tar.bz2 https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2

gmpのインストール

#cd gmp-6.1.0
#./configure --prefix=/usr/local/related/gmp-6.1.0
#make && make install

mpfrのインストール

#cd mpfr-3.1.6
#./configure --prefix=/usr/local/related/mpfr-3.1.6 --with-gmp=/usr/local/related/gmp-6.1.0
#make && make install

mpcのインストール

#cd mpc-1.0.3
#./configure --prefix=/usr/local/related/mpc-1.0.3 \
--with-gmp=/usr/local/related/gmp-6.1.0 \
--with-mpfr=/usr/local/related/mpfr-3.1.6
#make && make install

islのインストール

#cd isl-0.18
#./configure --prefix=/usr/local/related/isl-0.18 --with-gmp=/usr/local/related/gmp-6.1.0
#make && make install

2、gccのインストール

まず、gccビルド・ディレクトリーを作成する

#cd gcc-11.2.0 && mkdir build && cd build

コンパイル・パラメータの追加

#../configure --prefix=/opt/gcc-11.2.0 \
--enable-checking=release \
--enable-languages=c,c++ \
--disable-multilib
/* 依存関係を手動でインストールするには、以下のパスを指定する必要がある。
--with-gmp=/usr/local/related/gmp-6.1.0 \
--with-mpfr=/usr/local/related/mpfr-3.1.6 \
--with-mpc=/usr/local/related/mpc-1.0.3
*/

エラーなしで実行する

make && make install

プロセスは長く、何時間もかかるかもしれない

3、gccを代替ツールで管理する

代替の使用法:シンボリックリンク、バージョン選択、サービス選択を維持することにより、システムで使用されるデフォルトコマンドを決定する。

最初にオリジナルのgccをバックアップする

#mv /usr/bin/gcc /usr/bin/gcc-4.8.5
#mv /usr/bin/g++ /usr/bin/g++-4.8.5

代替リンクを使用する

#alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 88 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8.5
#alternatives --install /usr/bin/gcc gcc /opt/gcc-10.2.0/bin/x86_64-pc-linux-gnu-gcc 99 --slave /usr/bin/g++ g++ /opt/gcc-10.2.0/bin/x86_64-pc-linux-gnu-g++

システム・デフォルトのgccバージョンを選択するには、以下の選択肢を使用する。

#alternatives --config gcc
There are 2 programs which provide 'gcc'.
Selection Command
-----------------------------------------------
1 /usr/bin/gcc-4.8.5
*+ 2 /opt/gcc-11.2.0/bin/x86_64-pc-linux-gnu-gcc
Enter to keep the current selection[+], or type selection number: 2 # ここにシリアル番号を入力し、gccのバージョンを選択する。

現在のgccバージョンを見る

#gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-11.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)
#g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc-11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/opt/gcc-11.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)

4、ライブラリーリンクの更新

ライブラリ・リンクを更新しない場合、通常、次のようなエラーが報告されます:

/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.21' not found
/lib64/libstdc++.so.6: version 'GLIBCXX_3.4.22' not found

2つの更新方法 1つ目はシンプルで残酷なものだ。

#find / -name libstdc++.so.6
#rm -rf /usr/lib64/libstdc++.so.6
#ln -s /opt/gcc-11.2.0/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6

2回目の追加

#echo "/opt/gcc-11.2.0/lib64" >> /etc/ld.so.conf
#ldconfig

現在含まれているライブラリを見る

#strings /usr/lib64/libstdc++.so.6 | grep GLIBC
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29