Ubuntu – How to build and install gcc-5.4.0 on Ubuntu 18.04

gcc

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?

Best Answer

  • ... 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.

  • Related Question