Hugonweb | Building GCC From Source

See also: Building Clang From Source

Install the prereqs (for amd64 arch Ubuntu):

sudo apt install build-essential libc6-dev libc6-dev-i386 libgmp-dev libmpfr-dev libmpc-dev libzstd-dev

Download gcc from https://gcc.gnu.org.

Un-tar the archive into a folder, cd inside, then mkdir build; cd build. Then run:

../configure --program-suffix=-12.2.0 --enable-languages=c,c++,lto
nice make -j8
sudo make install

This installs into /usr/local with the executables in /usr/local/bin with suffix like "gcc-12.2.0".

Cross-compilers

To also build cross-compilers, make a new directory, and then use the same commands as before, but with additional options: