The guide will show you how to build GCC 6.2.0, as always with this kind of thing results may vary, I tested this on Debian 8 x64 and it worked fine, although I did do a fresh build of binutils.
- gcc, g++, binutils and make as well as your Linux kernel headers
- Additional requirements are gzip, bzip2, tar, perl, awk, GNAT (for Ada), DejaGNU, TCL and Expect, most of this should be present on most distributions.
- A good amount of free disk space, 20GB suggested
- You may need gcc multilib if you want to build a multilib version
Download GCC 6.2.0 here and unpack it, I recommend the following directory structure:
Before you build you need to install the prerequisite libraries GMP, MPC, MPFR and ISL in to the source tree, this can be done manually but it’s usually easier to use the included script.
cd gcc-6.2.0 ./contrib/download_prerequisites
One thing I always suggest adding is –disable-nls which remove the native language error messages which are not really needed.
cd build ../gcc-6.2.0/configure --prefix=/usr/local --enable-languages=c,c++ --disable-nls --host=x86_64-linux-gnu --build=x86_64-linux-gnu --target=x86_64-linux-gnu --with-tune=generic
I strongly recommend reading the documentation to ensure you have it configured how you want, the host, build and target options are probably not needed unless it gets confused with what your system is as mine did.
The build process it quite painless although it will take some time since it does essentially three complete builds, this can be disabled with –disable-bootstrap but it’s not at all recommended except for testing, for a fairly modern machine expect 30 minutes, for an older machine you may need to give it some hours.
make -j9 make check -j9 make install
The number adjusts the number processor threads used, 1 plus your total is usually good and will give a significant speed boost.
If you’re really short on space try make bootstrap-lean -j9 instead.Running the check is extremely important, if you get more than a few errors it’s strongly recommended that you not use it.
You should get something like this:
Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-gnu/6.2.0/lto-wrapper Target: x86_64-linux-gnu Configured with: ../gcc-6.2.0/configure --prefix=/usr/local --enable-languages=c,c++ --disable-nls --host=x86_64-linux-gnu --build=x86_64-linux-gnu target=x86_64-linux-gnu --with-tune=generic Thread model: posix gcc version 6.2.0 (GCC)
Since /usr/local/bin is typically in at the front of your PATH variable it will replace your installed gcc, to prevent this I suggest using –program-prefix=prefix or –program-suffix=suffix or installing it outside of /usr/local.
A final test would be to compile something and check if it works as expected.