Building GCC from source - chhwang/devel-note GitHub Wiki
-
Download Ubuntu package source code named
gcc-x_x.y.z.orig.tar.gz
. Example link: gcc-8 8.2.0-1ubuntu2 -
Extract and compile. Referred from GCC wiki.
tar xzf gcc-8_8.2.0.orig.tar.gz cd gcc-8_8.2.0 tar xf gcc-8.2.0.tar.xz cd gcc-8.2.0 ./contrib/download_prerequisites cd .. mkdir objdir cd objdir $PWD/../gcc-8.2.0/configure --prefix=$HOME/gcc-8.2.0 --enable-languages=c,c++,fortran,go --disable-multilib make make install
--prefix
means installation path. -
Update alternatives for
/usr/bin/gcc
.sudo update-alternatives --install /usr/bin/gcc gcc $HOME/gcc-8.2.0 90 sudo update-alternatives --config gcc
The number
90
means priority of this alternative (larger number higher priority).
Tip 1: some versions do have compile bugs. Search for patches or select another version.
Tip 2: --disable-multilib
means we use only for 64-bit machines. In my case make
failed when this option is missing in configuration.
Tip 3: gcc-5.4.0 has a bug that the make
fails if g++
is not already installed .