Help us understand the problem. What is going on with this article?

CentOS 8で様々なバージョンのGCCをビルドしてみた

はじめに

色々頑張りましたが、
CentOS8へCentOS7のcompat-gcc-44-4.4.7をインストール - Qiitaで問題が解決しました。

また、標準のGCC8.2.1でも以下のいずれかを指定することでruby以外うまく行きました。

CXXFLAGS="-std=gnu++98"

CXXFLAGS="-std=gnu++03"

CXXFLAGS="-std=c++98"

スクリーンショット_2019-10-30_12-32-09.png

以下メモ

ビルド結果

rpm作りました。使うときは

yum groupinstall -y -q "Development Tools"

export CC=/opt/gcc-6.5.0/bin/gcc
export CXX=/opt/gcc-6.5.0/bin/g++

yum remove -y gcc c++

update-alternatives \
 --install /usr/bin/gcc gcc /opt/gcc-6.5.0/bin/gcc 20 \
 --slave   /usr/bin/g++ g++ /opt/gcc-6.5.0/bin/g++

で hello.c がコンパイル成功。

hello.c
#include <stdio.h>

int main(void)
{
    printf("hello, world\n");
    return 0;
}

CentOS8標準のGCC8.2.1でビルドした結果

GCC ビルド compiler
4.3.6 x 8.2.1
4.4.7 x 8.2.1
4.5.4 x 8.2.1
4.9.4 x 8.2.1
5.5.0 x 8.2.1
6.5.0 o 8.2.1
7.4.0 o 8.2.1
8.3.0 o 8.2.1
9.2.0 o 8.2.1

CentOS8でビルドした GCC 6.5.0 を使ってビルドした結果

GCC ビルド compiler
4.9.4 x 6.5.0
5.5.0 x 6.5.0

CentOS7でビルドした GCC 4.4.7 を使ってビルドした結果

GCC ビルド compiler
3.4.6 x 4.4.7
4.4.7 x 4.4.7
5.5.0 x 4.4.7
6.5.0 x 4.4.7
環境(CentOS8.0.1905)
[root@82876b25c48b src]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC) 
Dockerfile.centos8
FROM centos:centos8

RUN yum groupinstall -y -q "Development Tools" && yum clean all
WORKDIR /usr/local/src/
RUN yum install -y gmp-devel mpfr-devel ncurses-devel wget wget zlib-devel


#----------
# fpm
#----------
RUN yum -y install ruby ruby-devel ruby-libs rubygems rpm-build \
 && gem install fpm --no-rdoc --no-ri

#----------
# gcc 6.5.0
#----------
COPY ./files.centos8/gcc-6.5.0.tar.gz gcc-6.5.0.tar.gz 
RUN tar xzf gcc-6.5.0.tar.gz 
WORKDIR /usr/local/src/gcc-6.5.0/
RUN ./contrib/download_prerequisites

# --disable-bootstrap
RUN ./configure \
 --prefix=/opt/gcc-6.5.0 \
 --with-bugurl=http://bugzilla.redhat.com/bugzilla \
 --enable-bootstrap \
 --enable-shared \
 --enable-threads=posix \
 --enable-checking=release \
 --with-system-zlib \
 --enable-__cxa_atexit \
 --disable-libunwind-exceptions \
 --enable-gnu-unique-object \
 --enable-languages=c,c++ \
 --disable-dssi \
 --enable-libgcj-multifile \
 --with-ppl \
 --with-cloog \
 --with-tune=generic \
 --disable-multilib \
 --build=x86_64-redhat-linux

RUN make -s
RUN make install

RUN fpm -s dir \
  -v 6.5.0 \
  -t rpm \
  -n opt-gcc-6.5.0 \
  -p opt-gcc-6.5.0.el8.x86_64.rpm \
  -C /opt/gcc-6.5.0 \
  --prefix /opt/gcc-6.5.0 \
  -a x86_64 \
  .

#-------------
# alternatives
#-------------
RUN yum remove -y gcc gcc-c++ \
 && update-alternatives \
 --install /usr/bin/gcc gcc /opt/gcc-6.5.0/bin/gcc 20 \
 --slave   /usr/bin/g++ g++ /opt/gcc-6.5.0/bin/g++
ENV CC=/opt/gcc-6.5.0/bin/gcc
ENV CXX=/opt/gcc-6.5.0/bin/g++

失敗 ( GCC 8.2.1 )

GCC 4.3.6

4.3.6.png

GCC 4.4.7

# configure: error: Building GCC requires GMP 4.1+ and MPFR 2.3.2+.

yum install -y \
  gmp-devel mpfr-devel
4.4.7
./configure \
 --enable-languages=c,c++ \
 --prefix=/opt/gcc-4.4.7 \
 --disable-bootstrap \
 --disable-multilib
export CXXFLAGS="-std=c++0x"

make -s

4.4.7.png

GCC 4.5.4

# ./contrib/download_prerequisites が無いため、 GCC 4.6.4 の中から持ってくる。

./contrib/download_prerequisites

./configure \
 --enable-languages=c,c++ \
 --prefix=/opt/gcc \
 --disable-bootstrap \
 --disable-multilib

err.png

GCC 4.9.4

4.9.4.png

GCC 5.5.0

5.5.0.png

成功 ( GCC 8.2.1 )

GCC 6.5.0

6.5.0
./contrib/download_prerequisites

./configure \
 --enable-languages=c,c++ \
 --prefix=/opt/gcc \
 --disable-bootstrap \
 --disable-multilib

make -s
make install

6.5.0.png

6.5.0.png

GCC 7.4.0

7.4.0.png
7.4.0.png

GCC 8.3.0

8.3.0.png
8.3.0.png

GCC 9.2.0

9.2.0.png
9.2.0.png

失敗 ( GCC 6.5.0 )

GCC 4.9.4

gccerror.png

GCC 5.5.0

550.png

その他

testgen

使用方法
yum install -y dejagnu

tar xf testgen20070902.tar.bz2

cd testgen20070902

# tgen.confのデータ長の情報を編集. longを 8byteにする
./bin/tgen.pl ./template/*.tt

cd testsuite
# 時間がかかる
./RUNTEST

testgen2

sudo yum install -y perl-Time-HiRes

unzip testgen20070902.zip
cd testgen20070902

perl bin/tgen.pl --config=config/tgen.cnf template/*.tt
cd testsuite/
# 時間がかかる
./runtest.pl

スクリーンショット_2019-10-08_13-54-55.png
スクリーンショット 2019-10-10 17.44.57.png

mysql 4.0.30

export CXXFLAGS="-std=c++98"

でビルド成功した。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした