How Do I Install GCC 7.3.0?
Perform the following steps as the root user.
- Download gcc-7.3.0.tar.gz from https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz.
- To install GCC, you need to reserve adequate temporary space. You can run the following command to clear the /tmp directory in advance:
sudo rm -rf /tmp/*
- Install the dependency.
For CentOS/BCLinux, run the following command:
yum install bzip2
For Ubuntu/Debian, run the following command:
apt-get install bzip2
- Build and install GCC.
- Go to the directory where the source code package gcc-7.3.0.tar.gz is located and run the following command to extract it:
tar -zxvf gcc-7.3.0.tar.gz
- Go to the extraction folder and download the GCC dependency package:
cd gcc-7.3.0 ./contrib/download_prerequisites
If an error is reported during the command execution, download the dependency packages to the gcc-7.3.0/ folder:
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 downloading the preceding dependency packages, run the following command:
./contrib/download_prerequisites
If the validation fails, check whether the dependency packages are repeatedly downloaded. The packages should be downloaded at a time.
- Run the following commands for configuration, build, and installation.
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/linux_gcc7.3.0 make -j15 # The value 15 indicates the number of CPUs, which is configurable and can be queried by running grep -w processor /proc/cpuinfo|wc -l. make install
The --prefix parameter is used to specify the linux_gcc7.3.0 installation path, which is configurable. Do not set it to /usr/local or /usr, which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to /usr/local/linux_gcc7.3.0.
- Go to the directory where the source code package gcc-7.3.0.tar.gz is located and run the following command to extract it:
- Set the environment variable.
The build environment after GCC upgrade is required for training. Therefore, you need to configure the following environment variable in the training script:
export LD_LIBRARY_PATH=.../xxx/xxx/xxx/lib64
In the preceding command, .../xxx/xxx/xxx/ is the GCC installation path configured in 3.. You need to configure the path. In this example, the path is /usr/local/linux_gcc7.3.0/.
The environment variable needs to be configured only when you need to use the build environment after the GCC upgrade.