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 is 7.3.0 on openEuler 20.03 and 10.3.1 on openEuler 22.03. Therefore, you do not need to upgrade them. As an example, the following procedure describes how to upgrade GCC to 7.3.0 on CentOS 7.6.

To upgrade GCC to 7.3.0 on CentOS 7.6, perform the following steps:

  1. Download GCC 7.3.0.
    1
    2
    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 the error message "configure: error: no acceptable C compiler found in $PATH" is reported, run the following command:

      1
      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. Check the GCC version.
    1
    gcc -v
    

    The GCC version has been upgraded to 7.3.0.