gcc-12.4.0をCentOS Stream 8にソースインストール

アフィリエイト広告を利用しています

このページの内容が役に立ったら X (旧twitter) でフォローして頂けると励みになります
挨拶や報告は無しで大丈夫です

MySQL 8.4.5 をインストールするために gcc-12.4.0 をインストールしました。

目的

MySQL 8.4.5 をインストールしようとしたところ CMake で次のエラーが発生しました。

---------------------------------------------
CMake Warning at CMakeLists.txt:390 (MESSAGE):
  Could not find devtoolset compiler/linker in /opt/rh/gcc-toolset-12


CMake Warning at CMakeLists.txt:392 (MESSAGE):
  You need to install the required packages:

   yum install gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc



CMake Error at CMakeLists.txt:394 (MESSAGE):
  Or you can set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly.
---------------------------------------------

特徴

  • ソースコードからのインストール
  • 複数バージョンの共存

特定バージョンでの開発や動作確認など開発環境での用途を目的としています。

環境

実施日2025-05-02
サーバさくらのVPS 2G
OSCentOS Stream 8
cat /etc/redhat-release
CentOS Stream release 8

事前準備

gcc の確認

gcc --version
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-6)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc-c++ の確認

g++ --version
g++ (GCC) 8.5.0 20210514 (Red Hat 8.5.0-6)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc-12.4.0

公式サイトからダウンロードして、/tmp  にアップロード

GCCの公式サイトに行くとダウンロードページへのリンクがあります。

トップページ右側の青いところ「Download」の「Mirrors」をクリック。
Japan: ftp.tsukuba.wide.ad.jp, ・・・ のところをクリック。
releases/ をクリック。

https://ftp.tsukuba.wide.ad.jp/software/gcc/releases

gcc-12.4.0/ をクリック。

「gcc-12.4.0.tar.gz」を右クリックしてURLをコピーします。

https://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-12.4.0/gcc-12.4.0.tar.gz

インストール

ls -la /usr/local/src
ls -la /usr/local/lib
mkdir /usr/local/src/gcc-12.4.0
cd /usr/local/src/gcc-12.4.0
wget https://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-12.4.0/gcc-12.4.0.tar.gz
tar xvzf gcc-12.4.0.tar.gz
cd gcc-12.4.0
./contrib/download_prerequisites
cd ..
mkdir build
cd build
../gcc-12.4.0/configure \
    --enable-languages=c,c++ \
    --prefix=/usr/local/lib/gcc-12.4.0 \
    --disable-bootstrap \
    --disable-multilib \
    --with-native-system-header-dir=/usr/include
make -j$(nproc)
make -j$(nproc)
make install
/usr/local/lib/gcc-12.4.0/bin/gcc -v
/usr/local/lib/gcc-12.4.0/bin/g++ -v

一時的に有効にする

export PATH=/usr/local/gcc-12.4.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/gcc-12.4.0/lib64:$LD_LIBRARY_PATH
gcc -v
g++ -v