Rate This Document
Findability
Accuracy
Completeness
Readability

Installing GCC

The built-in GCC software on CentOS 7.6 is too early. Upgrade GCC to 5.3.0 or later. The GCC version of openEuler 20.03 is 7.3.0 and does not need to be upgraded. To install Percona 8.0.15 on openEuler 22.03 (GCC provided by the OS is 10.3.1), install GCC 7.3.0.

For details about how to upgrade to GCC 7.3.0 on CentOS 7.6, see Upgrading GCC on CentOS 7.6. For details about how to install GCC 7.3.0 on openEuler 22.03, see Installing GCC 7.3.0 on openEuler 22.03.

Upgrading GCC on CentOS 7.6

  1. Download GCC 7.3.0.
    cd /home
    wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz --no-check-certificate
  2. Decompress the GCC source package.
    1
    tar -xvf gcc-7.3.0.tar.gz
    

  3. Compile and install GCC.
    1. Go to the GCC file path and set GCC parameters.
      1
      2
      cd /home/gcc-7.3.0
      ./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-bootstrap
      

      • --prefix=PATH: specifies the GCC installation directory. The default directory is /usr.
      • --mandir=PATH: specifies the directory for storing GCC files. The default directory is /usr/share/man.
      • --infodir=PATH: specifies the directory for storing GCC logs. The default directory is /usr/share/info.
      • --enable-bootstrap: enables bootstrap installation.

      If an error is reported stating "configure: error: no acceptable C compiler found in $PATH", run the following command:

      yum -y reinstall gcc gcc-c++
    2. Compile the GCC source code.
      1
      make -j 96
      

      In the command, -j 96 can make full use of the multi-core feature of the CPUs to accelerate the compilation. The number following -j indicates the number of CPU cores. You can run the cat /proc/cpuinfo | grep processor | wc -l command to query the number of CPU cores. The value specified must be less than or equal to the actual number of CPU cores.

    3. Install GCC.
      1
      make -j 96 install
      
  4. View the GCC version.
    1
    gcc -v
    

    The GCC version has been upgraded to 7.3.0.

Installing GCC 7.3.0 on openEuler 22.03

  1. Download the gmp source package and decompress it.
    mkdir /home/gcc-7.3.0 && cd /home/gcc-7.3.0
    wget https://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.bz2
    tar -jxvf gmp-6.1.0.tar.bz2
  2. Create a gmp compilation directory and perform compilation and installation.
    cd gmp-6.1.0
    mkdir build && cd build
    ../configure --prefix=/opt/tools/gcc/gmp-6.1.0
    make
    make install

    --prefix=/opt/ltools/gcc/gmp-6.1.0 specifies the gmp installation directory. If the installation directory does not exist, it is automatically created when running the preceding command.

  3. Download the mpfr source package and decompress it.
    cd /home/gcc-7.3.0
    wget https://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.bz2
    tar -jxvf mpfr-3.1.4.tar.bz2
  4. Create an mpfr compilation directory and perform compilation and installation.
    cd mpfr-3.1.4
    mkdir build && cd build
    ../configure --prefix=/opt/tools/gcc/mpfr-3.1.4 --with-gmp=/opt/tools/gcc/gmp-6.1.0
    make
    make install

    --prefix=/opt/tools/gcc/mpfr-3.1.4 specifies the mpfr installation directory. If the installation directory does not exist, it is automatically created when running the preceding command.

  5. Download the mpc source package and decompress it.
    cd /home/gcc-7.3.0
    wget https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
    tar -zxvf mpc-1.0.3.tar.gz
  6. Create an mpc compilation directory and perform compilation and installation.
    cd mpc-1.0.3
    mkdir build && cd build
    ../configure --prefix=/opt/tools/gcc/mpc-1.0.3 --with-gmp=/opt/tools/gcc/gmp-6.1.0 --with-mpfr=/opt/tools/gcc/mpfr-3.1.4
    make
    make install

    --prefix=/opt/tools/gcc/mpc-1.0.3 specifies the mpc installation directory. If the installation directory does not exist, it is automatically created when running the preceding command.

  7. Download the isl source package and decompress it.
    cd /home/gcc-7.3.0
    wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
    tar -jxvf isl-0.16.1.tar.bz2
  8. Create an isl compilation directory and perform compilation and installation.
    cd isl-0.16.1
    mkdir build && cd build
    ../configure -prefix=/opt/tools/gcc/isl-0.16.1 -with-gmp-prefix=/opt/tools/gcc/gmp-6.1.0
    make
    make install

    -prefix=/opt/tools/gcc/isl-0.16.1 specifies the isl installation directory. If the installation directory does not exist, it is automatically created when running the preceding command.

  9. Set environment variables.
    export LD_LIBRARY_PATH=/opt/tools/gcc/gmp-6.1.0/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH=/opt/tools/gcc/mpfr-3.1.4/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH=/opt/tools/gcc/mpc-1.0.3/lib:${LD_LIBRARY_PATH}
    export LD_LIBRARY_PATH=/opt/tools/gcc/isl-0.16.1/lib:${LD_LIBRARY_PATH}
  10. Reload the environment variable settings.
    source /etc/profile
  11. Download the GCC source package and decompress it.
    cd /home/gcc-7.3.0
    wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
    tar -xvzf gcc-7.3.0.tar.gz
  12. Create a GCC compilation directory and perform compilation and installation. The compilation takes about 30 minutes.
    cd gcc-7.3.0
    mkdir build && cd build
    ../configure --prefix=/opt/tools/gcc/gcc-7.3.0 --enable-threads=posix --disable-checking --enable--long-long --enable-languages=c,c++ --with-gmp=/opt/tools/gcc/gmp-6.1.0 --with-mpfr=/opt/tools/gcc/mpfr-3.1.4 --with-mpc=/opt/tools/gcc/mpc-1.0.3 --disable-multilib
    make -j 96
    make install
    • --prefix=/opt/tools/gcc/gcc-7.3.0 specifies the GCC installation directory. If the installation directory does not exist, it is automatically created when running the preceding command.
    • In the command, -j 96 can make full use of the multi-core feature of the CPUs to accelerate the compilation. The number following -j indicates the number of CPU cores. You can run the cat /proc/cpuinfo | grep processor | wc -l command to query the number of CPU cores. The value specified must be less than or equal to the actual number of CPU cores.
  13. Check the GCC version.
    /opt/tools/gcc/gcc-7.3.0/bin/gcc --version