GCC is a basic tool. If it is installed by multiple users, conflicts may occur. Therefore, you are advised to perform the following steps as the root user.
1 | rm -rf /tmp/* |
1 | yum install bzip2 |
1 | apt-get install bzip2 |
1 | tar -zxvf gcc-7.3.0.tar.gz --no-same-owner |
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 in 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 again:
1 | ./contrib/download_prerequisites |
If the preceding command fails, ensure that the dependencies are successfully downloaded at a time and no repeated download occurs.
1 | ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0 |
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.
1 | 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 parameter as required. |
1 | make install
|
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.