Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dongguangming/73567cb41b15c274bcd1844e2dc0bd23 to your computer and use it in GitHub Desktop.
Save dongguangming/73567cb41b15c274bcd1844e2dc0bd23 to your computer and use it in GitHub Desktop.

Revisions

  1. @nchaigne nchaigne revised this gist Oct 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion build-gcc-9.2.0-on-centos7.md
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ Required support libraries, listed hereafter, can be downloaded automatically us
    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.
    - Make sure you have enough space in `/home/build` (or whatever location you choose). You will need ~1 GB for gcc sources, ~6 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).
    - Option `--enable-langagues` allows to have a leaner and faster build if you only need (for example) C and C++.
  2. @nchaigne nchaigne created this gist Oct 27, 2019.
    53 changes: 53 additions & 0 deletions build-gcc-9.2.0-on-centos7.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@

    # Building GCC 9.2.0 on CentOS 7

    ## Introduction

    CentOS 7 distribution (as well as RHEL 7) ships with a somewhat outdated version of the GCC compiler (4.8.5 on CentOS 7.5), which may not be suitable to your compilation requirements. For example, [C11](https://gcc.gnu.org/wiki/C11Status) - which supersedes C99 - is fully supported only starting from GCC 4.9).

    Additionally, recent versions of GCC ([GCC6](https://gcc.gnu.org/gcc-6/changes.html), [GCC7](https://gcc.gnu.org/gcc-7/changes.html), [GCC8](https://gcc.gnu.org/gcc-8/changes.html), [GCC9](https://gcc.gnu.org/gcc-9/changes.html)) 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 (9.2.0 as of October 2019) from sources on CentOS 7. This should be applicable as is on RHEL 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++`__
    Required support libraries, listed hereafter, can be downloaded automatically using script `download_prerequisites` included in the GCC archive. It's convenient, so we'll do that.

    - [GNU Multiple Precision Library](https://gmplib.org/) (GMP) version 4.3.2 (or later)
    - [MPFR Library](http://www.mpfr.org/) version 2.4.2 (or later)
    - [MPC Library](http://www.multiprecision.org/mpc/) version 0.8.1 (or later)
    - [ISL library](http://isl.gforge.inria.fr/) version 0.15 (or later)



    ## Build and install gcc

    >__`cd /home/build`__<br>
    >__`GCC_VERSION=9.2.0`__<br>
    >__`wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz`__<br>
    >__`tar xzvf gcc-${GCC_VERSION}.tar.gz`__<br>
    >__`mkdir obj.gcc-${GCC_VERSION}`__<br>
    >__`cd gcc-${GCC_VERSION}`__<br>
    >__`./contrib/download_prerequisites`__<br>
    >__`cd ../obj.gcc-${GCC_VERSION}`__<br>
    >__`../gcc-${GCC_VERSION}/configure --disable-multilib --enable-languages=c,c++`__<br>
    >__`make -j $(nproc)`__<br>
    >__`make install`__<br>
    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).
    - Option `--enable-langagues` allows to have a leaner and faster build if you only need (for example) C and C++.
    - See [GCC documentation](https://gcc.gnu.org/install/configure.html) for the full list of configure options.