Build gcc-5 on Ubuntu 20.04
with gcc-9
. Problems listed here are fixed and tested.
Make sure gcc-9
is installed on your distro. gcc
other than version 9 and 11 are NOT tested.
gcc-11
is tested to be too new to build gcc-5
as discussed here. In practical, an error would be thrown:
use of an operand of type ‘bool’ in ‘operator++’ is forbidden in C++17
git clone https://github.com/AdorableJiang/gcc-5.4.0.git
cd gcc-5.4.0
./contrib/download_prerequisites
mkdir gcc-build-5.4.0
cd gcc-build-5.4.0
CC=[/path/to/gcc-9] CXX=[/path/to/g++-9] ../configure --prefix=/usr/local --enable-checking=release --enable-languages=c,c++ --disable-multilib
For explanation of gcc-5.4.0/configure
options, check section Options specification
of Installing GCC: Configuration.
Now you are all set to build gcc-5
.
make -j$(nproc)
sudo make install
The built gcc-5
binaries should be installed to --prefix/gcc-5.4.0/bin
,
$/usr/local/gcc-5.4.0/bin/gcc --version
gcc (GCC) 5.4.0
Copyright © 2015 Free Software Foundation, Inc.
and for g++
$/usr/local/gcc-5.4.0/bin/g++ --version
g++ (GCC) 5.4.0
Copyright © 2015 Free Software Foundation, Inc.
If you encountered problems using this repo, check here or cached offline reference/ubuntu_install_gcc5.4.html
for help.
To uninstall gcc installed from source, run uninstall.sh
under gcc build directory as root. That is gcc-build-5.4.0
if you follow the instructions above.
cp uninstall.sh gcc-build-5.4.0/ && cd gcc-build-5.4.0/
sudo bash uninstall.sh
Reference: How to uninstall gcc installed from source?