2

I have tried several methods for build and install gcc-5.4.0 on my PC;

I ran this code:

GCC_VERSION="5.4.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"

cd $WORKDIR
wget http://www.netgull.com/gcc/releases/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2
tar -xf gcc-${GCC_VERSION}.tar.bz2

cd gcc-${GCC_VERSION}
./contrib/download_prerequisites

cd ..
mkdir gcc-build
cd gcc-build

../gcc-${GCC_VERSION}/configure                      \
    --prefix=${INSTALLDIR}                           \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --enable-clocale=gnu                             \
    --enable-languages=all                           \
&& make \
&& make install

which did not work; telling me that I should disable multi-lib.

I did it using this code:

GCC_VERSION="5.4.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"

cd $WORKDIR
wget http://www.netgull.com/gcc/releases/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2
tar -xf gcc-${GCC_VERSION}.tar.bz2

cd gcc-${GCC_VERSION}
./contrib/download_prerequisites

cd ..
mkdir gcc-build
cd gcc-build

../gcc-${GCC_VERSION}/configure                      \
    --prefix=${INSTALLDIR}                           \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --enable-clocale=gnu                             \
    --enable-languages=all                           \
    --disable-multilib                               \
&& make \
&& make install

which was running for almost half an hour and made a directory as big as 1 GB. So I doubted the source file and interrupted it.

Then I tried downloading gcc-5.4.0 from another source.

Compiled with the following command:

GCC_VERSION="5.4.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"

cd $WORKDIR
wget http://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.bz2
tar -xf gcc-${GCC_VERSION}.tar.bz2

cd gcc-${GCC_VERSION}
./contrib/download_prerequisites

cd ..
mkdir gcc-build
cd gcc-build

../gcc-${GCC_VERSION}/configure                      \
    --prefix=${INSTALLDIR}                           \
    --disable-multilib                               \
    --enable-shared                                  \
    --enable-threads=posix                           \
    --enable-__cxa_atexit                            \
    --enable-clocale=gnu                             \
    --enable-languages=all                           \
&& make \
&& make install

Again I got an error, do you know any direct way that I can do that?

Mone
  • 31

5 Answers5

1

... which was running for almost half an hour and made a directory as big as 1 GB. So I doubted the source file and interrupted it.

It's possible that you're on the right track, and rushed into stopping the build prematurely. Depending on the strength of your machine, 30 minutes doesn't sound unreasonable time for building GCC. Most importantly, you're building using make, which means that source files are compiled serially, one at a time, which is make's default. For speeding up the build significantly, run make -j, which will build parallely using all CPU cores, or make -j4 for running 4 parallel compile jobs, for example.

As for build size, I suspect that by default, GCC builds in Debug mode, which would explain the bloated build folder (for comparison, LLVM debug build could easily stack up to > 4GB).

However, if you don't have to build your own copy of GCC from source, you could use pre-built 5.4 packages available on Launchpad.

For GCC (C only), grab the .deb files and install them in order:

mkdir ~/Downloads/gcc-5.4-deb && cd ~/Downloads/gcc-5.4-deb

wget http://launchpadlibrarian.net/375474546/gcc-5-base_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474798/libasan2_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474828/libmpx0_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474805/libgcc-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474748/cpp-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474755/gcc-5_5.4.0-6ubuntu1~16.04.10_amd64.deb

sudo dpkg -i gcc-5-base_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libasan2_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libmpx0_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libgcc-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i cpp-5_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i gcc-5_5.4.0-6ubuntu1~16.04.10_amd64.deb

For C++ support, add the following:

wget http://launchpadlibrarian.net/375474836/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474834/libstdc++-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://launchpadlibrarian.net/375474751/g++-5_5.4.0-6ubuntu1~16.04.10_amd64.deb

sudo dpkg -i libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i libstdc++-5-dev_5.4.0-6ubuntu1~16.04.10_amd64.deb
sudo dpkg -i g++-5_5.4.0-6ubuntu1~16.04.10_amd64.deb

Do note that, downgrading libstdc++6 may cause breakage of some packages (for example, cmake and firefox on my Ubuntu 18.10). Keeping multiple libstdc++'s is technically possible, but difficult to accomplish and surely not ideal.

valiano
  • 1,985
1

I had to install the following packages in addition to what valiano mentioned:

wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libcilkrts5_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libubsan0_5.4.0-6ubuntu1~16.04.10_amd64.deb
wget http://cz.archive.ubuntu.com/ubuntu/pool/main/i/isl/libisl15_0.16.1-1_amd64.deb
wget http://cz.archive.ubuntu.com/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.4-1_amd64.deb
1

New gcc-5 builds are documented at: https://launchpad.net/ubuntu/+source/gcc-5

From there you should be able to click on one of the builds with the version you need and then under "Builds" -> "amd64" (or your architecture) you will find the appropriate binaries.

You probably only need the packages listed below:

# Taken from the build at https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/gcc-5-base_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/libasan2_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/libmpx0_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/libcilkrts5_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/libubsan0_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/libgcc-5-dev_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/cpp-5_5.4.0-6ubuntu1~16.04.12_amd64.deb
wget https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/3807-deletedppa/+build/17785138/+files/gcc-5_5.4.0-6ubuntu1~16.04.12_amd64.deb

These two are taken from DannyDahan's solution. A newer version from launchpad may have worked aswell

wget http://cz.archive.ubuntu.com/ubuntu/pool/main/i/isl/libisl15_0.16.1-1_amd64.deb wget http://cz.archive.ubuntu.com/ubuntu/pool/main/m/mpfr4/libmpfr4_3.1.4-1_amd64.deb

dpkg -i gcc-5-base_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i libcilkrts5_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i libubsan0_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i libmpx0_5.4.0-6ubuntu1~16.04.12_amd64.deb

dpkg -i libisl15_0.16.1-1_amd64.deb dpkg -i libmpfr4_3.1.4-1_amd64.deb

dpkg -i cpp-5_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i libasan2_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i libgcc-5-dev_5.4.0-6ubuntu1~16.04.12_amd64.deb dpkg -i gcc-5_5.4.0-6ubuntu1~16.04.12_amd64.deb

0

The difference between gcc 5.5.0 and gcc 5.4 is so minimal that maybe you'll never know the difference. I have gcc 5.5.0 (gcc-5) installed in Ubuntu 18.04, and I'm not aware of any functionality that's missing because I don't have gcc 5.4 installed too.

You don't need to build gcc-5 in Ubuntu 18.04; instead it can be installed with apt. To install gcc 5.5.0 in Ubuntu 18.04 open the terminal and type:

sudo apt install gcc-5  

Multiple versions of gcc can be installed alongside each other in Ubuntu 18.04, for example gcc-5 and gcc-8. You can change the default gcc version by using the update-alternatives command to determine which actual file is referenced by a generic name, for example which actual file is referenced by gcc. For more information see the answers to this question: How to change the default GCC compiler in Ubuntu?.

karel
  • 114,770
0

When the package is already half a gigabyte, it's a gigabyte when unpacking the sources.

But switch --disable-multilib is non-sense when building a C/C++ compiler.

The error message disable multi-lib means: cannot build 32-bit assembly, because missing the 32-bit glibc library. I've ran into this issue yesterday and needed to install yum install glibc-devel.i686. On Ubuntu Linux, this should be apt-get install glibc-dev.i386 or probably libc6-dev-i386. Just manually provide the packages it depends upon, or fix that (probably outdated) ./contrib/download_prerequisites shell script to include this package.

Else you'll end up with a compiler that cannot build for x86, but only x86_64.