我要评分
获取效率
正确性
完整性
易理解

Compiler and Compilation Options

Using GCC of a Later Version

Upgrade the GCC in Ubuntu to GCC 10.1.0.

  1. Obtain the latest GCC source package.

    To obtain the source package, visit http://ftp.gnu.org/gnu/gcc/gcc-10.1.0.

  2. Decompress the obtained package.
    tar -xzvf gcc-10.1.0.tar.gz

  3. Go to the directory generated after the decompression and run the download_prerequisites script.
    cd gcc-10.1.0/
    ./contrib/download_prerequisites

    The download_prerequisites script file is used to download, configure, and install the dependency library.

  4. Run the following commands to create a directory and save the output of the download_prerequisites script to the directory:
    mkdir gcc_temp
    cd gcc_temp
    ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

  5. Perform the compilation and installation.
    1. Perform the compilation.
      make -j32

      The compilation may last one to two hours. Pay attention to the time arrangement before the compilation.

    2. Perform the installation.
      • Performing the installation as the root user:
        make install
      • Performing the installation as a common user:
        sudo make install
        Figure 1 Installation process
  6. Verify the installation.

    Run any of the following commands to check the GCC version:

    gcc --version
    gcc -v
    g++ -v

    If the displayed GCC version is earlier than the required version, restart the system. Alternatively, run the which gcc command to check the GCC installation directory, and then run the /usr/local/bin/gcc -v command to check the version information. Generally, the GCC is installed in the directory.

    Figure 2 Installation succeeded