Skip to content

Instantly share code, notes, and snippets.

@nchaigne
Last active April 19, 2024 11:54
Show Gist options
  • Save nchaigne/9eba78dafb011b138fa513ea5fd016a8 to your computer and use it in GitHub Desktop.
Save nchaigne/9eba78dafb011b138fa513ea5fd016a8 to your computer and use it in GitHub Desktop.
Building GCC 7.3.0 on Red Hat Enterprise Linux 7

Building GCC 7.3.0 on Red Hat Enterprise Linux 7

Introduction

Red Hat Enterprise Linux (RHEL) distribution ships with a somewhat outdated version of the GCC compiler (4.8.3 on RHEL 7.1), which may not be suitable to your compilation requirements. For example, C11 - which supersedes C99 - is fully supported only starting from GCC 4.9).

Additionally, recent versions of GCC (GCC6, GCC7) come with improvements which help detect issues at build time and offer suggestions on how to fix them. Sometimes, these are even actually helpful!

This note describes how to build the latest GCC (7.3 as of January 2018) from sources on RHEL 7. This should be applicable as is on CentOS 7. For other Linux distributions, adapt as needed.

While this is not overly complicated, building GCC takes quite some time. So you might want to plan to do something else while it builds... a coffee break just won't make it.

Prerequisites

Prerequisites are described here: https://gcc.gnu.org/install/prerequisites.html

  • C++ compiler

yum install gcc gcc-c++

Note: gmp 6.0.0 should already be installed, but you need the headers.

yum install gmp gmp-devel

yum install mpfr mpfr-devel

My repository didn't have libmcp-devel available. You can get a CentOS 7 package (which will work just fine for RHEL 7), and install it manually. For example:

cd /home/build
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libmpc-devel-1.0.1-3.el7.x86_64.rpm
yum install libmpc-devel-1.0.1-3.el7.x86_64.rpm

Or you can build the latest version from sources:

cd /home/build
MPC_VERSION=1.1.0
wget https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz
cd mpc-${MPC_VERSION}
configure
make
make install

Build and install gcc

cd /home/build
GCC_VERSION=7.3.0
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
tar xzvf gcc-${GCC_VERSION}.tar.gz
mkdir obj.gcc-${GCC_VERSION}
cd obj.gcc-${GCC_VERSION}
../gcc-${GCC_VERSION}/configure --disable-multilib
make
make install

Notes:

  • If you have several processors available, you can benefit from a parallel build. For example, make -j 6 will use 6 CPUs. (You might want to save a few for yourself, so you can do things on your server while gcc builds.)
  • Make sure you have enough space in /home/build (or whatever location you choose). You will need ~700 MB for gcc sources, ~5.2 GB for the build). Be prepared.
  • This will install gcc in /usr/local/bin/gcc (default prefix is /usr/local). Your distro gcc (/usr/bin/gcc) will not be overwritten, but if later on you need to invoke it, you will have to do so explicitly. Configure with option --prefix if you want to change this.
  • Option --disable-multilib prevents building multiple target libraries (I don't need them, and it is simpler).
  • See GCC documentation for the full list of configure options.
@sfc-gh-dschumann
Copy link

Thanks for this manual!
One improvement: Instead of trying to mess around with installing GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. just execute contrib/download_prerequisites

@Ljohn001
Copy link

Ljohn001 commented Feb 1, 2023

Thanks for this manual!
MPC step, lack of decompression.

MPC_VERSION=1.1.0
wget https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz
tar zxvf mpc-${MPC_VERSION}.tar.gz
cd mpc-${MPC_VERSION}
configure
make
make install

@Hacker-Thor
Copy link

@sfc-gh-dschumann Can you tell me in this brief.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment