Installing GCC 7.3.0

Perform the following steps as the root user:

  1. In any directory (for example, /home) on the server, run the following command to obtain the gcc-7.3.0.tar.gz source package:
    1
    wget https://repo.huaweicloud.com/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
    

    If an error is reported, click here to manually download and upload the source package.

  2. The GCC installation occupies a large amount of temporary space. Therefore, run the following command to clear the /tmp directory:
    1
    rm -rf /tmp/*
    
  3. Install the dependencies based on the online installation mode of the system dependency packages.
    • For the openEuler series, run the following command:
      1
      yum install bzip2
      
    • For the Ubuntu series, run the following command:
      1
      apt-get install bzip2
      
  4. Compile and install GCC.
    1. Go to the directory where the gcc-7.3.0.tar.gz source package is located and run the following command to decompress the source package:
      1
      tar -zxvf gcc-7.3.0.tar.gz
      
    2. Go to the decompressed folder and download the GCC dependencies:
      1
      2
      cd gcc-7.3.0
      ./contrib/download_prerequisites
      

      If an error is reported during the execution of the preceding command, run the following commands to download the dependencies from the gcc-7.3.0/ folder:

      1
      2
      3
      4
      wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
      wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
      wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
      wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
      

      After the preceding dependencies are downloaded, run the following command:

      1
      ./contrib/download_prerequisites
      

      Check whether error information similar to the following is displayed:

      1
      2
      3
      gmp-6.1.0.tar.bz2: FAILED
      sha512sum: WARNING: 1 computed checksum did NOT match
      error: Cannot verify integrity of possibly corrupted file gmp-6.1.0.tar.bz2
      

      If yes, the GMP package may not be completely downloaded due to network problems. Run the rm -rf gmp-6.1.0.tar.bz2 command to delete the GMP package, and then run the wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 command to download the package again. Then, run the ./contrib/download_prerequisites command.

    3. Run the configuration, compilation, and installation commands.
      1
      2
      3
      ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0
      make -j15    # Check the number of CPUs by running grep -w processor /proc/cpuinfo|wc -l. In this example, the number is 15. You can set the parameters as required.
      make install    
      
      • The compilation takes about one hour.
      • The --prefix parameter is used to specify the GCC 7.3.0 installation path. You can set it as required. However, do not set it to /usr/local or /usr because they conflict with the GCC that is installed by default by the system using the software source. Otherwise, the original GCC compilation environment of the system will be damaged. In this example, use /usr/local/gcc7.3.0.
  5. Configure environment variables as required.

    Before starting the online inference or training process, run the following command to configure environment variables:

    1
    2
    3
    4
    export LD_LIBRARY_PATH=/usr/local/gcc7.3.0/lib64:${LD_LIBRARY_PATH}
    export CC=/usr/local/gcc7.3.0/bin/gcc
    export CXX=/usr/local/gcc7.3.0/bin/g++
    export PATH=/usr/local/gcc7.3.0/bin:${PATH}
    

    In the preceding command, /usr/local/gcc7.3.0 indicates the GCC 7.3.0 installation path configured in 4.c. Replace it with the actual path.

    Run the gcc --version command to check the GCC version. If the following information is displayed, the installation is successful:
    1
    gcc (GCC) 7.3.0
    

    To perform compilation using GCC 7.3.0 but the GCC version cannot be controlled using environment variables due to compilation script problems, perform the following operations to modify the soft link:

    1. Back up the soft link of the old version.
      1
      2
      3
      4
      mv /usr/bin/gcc /usr/bin/gcc.bak
      mv /usr/bin/g++ /usr/bin/g++.bak
      mv /usr/bin/c++ /usr/bin/c++.bak
      mv /usr/bin/cc /usr/bin/cc.bak
      
    2. Create a soft link for the new version.
      1
      2
      3
      4
      ln -s /usr/local/gcc7.3.0/bin/gcc /usr/bin/gcc
      ln -s /usr/local/gcc7.3.0/bin/g++ /usr/bin/g++
      ln -s /usr/local/gcc7.3.0/bin/c++ /usr/bin/c++
      ln -s /usr/local/gcc7.3.0/bin/gcc /usr/bin/cc
      
    3. Run the gcc --version command to check the GCC version. If the following information is displayed, the configuration is successful:
      1
      gcc (GCC) 7.3.0