Other centos series can be referred to, untested, if you have any questions, you can leave a message to discuss
Because some relatively new software requires the latest version of gcc, the version 4.8.5 installed by centos 7.2 using yum install gcc may not meet the requirements of the software. Here is how to toss the latest version of GCC
GCC official website: https://gcc.gnu.org/
My current version is 9.3, so we install the latest version:
01
Installation base dependent environment
yum install glibc-headers gcc-c++ gcc gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel
02
download
http://mirror.hust.edu.cn/gnu/gcc/
I chose gcc-9.3.0.tar.gz.
cd
mkdir software
cd software
wget http://mirror.hust.edu.cn/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
tar zxvf gcc-9.3.0.tar.gz
cd cc-9.3.0
03
Download the dependency package:
. /contrib/download_prerequisites
04
Configuration
mkdir build
cd build
../configure --prefix=/usr/local/gcc-9.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
configure is an executable script that has many options. Use the command ./configure –help to output a detailed list of options in the source path to be installed. The --prefix option is to configure the installation path.
If the --prefix option is not configured, after installation:
The executable file is placed in /usr /local/bin
by default,
The library files are placed in /usr/local/lib
by default,
The configuration file is placed in /usr/local/etc
by default,
Other resource files are placed in /usr /local/share
Detailed explanation of configure parameters:
- - prefix=/usr/local/gcc-9.3.0/
: Put all resource files under this path.
- - enable-checking=release
: The generated compiler does not perform additional checks during the compilation process.
- - enable-languages=c,c++
: Let gcc support c, c++.
- - disable-multilib
: Does not generate a cross-compiler compiled into executable code for other platforms.
05
Compile
make
This process takes a long time. Need to be patient
06
installation
make install
07
Aftermath
01
Delete the old version of gcc downloaded by yum
yum remove gcc
02
Add the new version of gcc to the command search path:
ln -s /usr/local/gcc-9.3.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-9.3.0/bin/g++/usr/bin/g++
03
Add LD_LIBRARY_PATH environment variable
Add the following code in /etc/profile:
# gccLD_LIBRARY_PATH=/usr/local/gcc-9.3.0/lib#export LD_LIBRARY_PATH
Execute after changing
source /etc/profile
04
Finally replace libstdc++.so.6
cp /usr/local/gcc-9.3.0/lib64/libstdc++.so.6.0.28/usr/lib64/libstdc++.so.6.0.28
rm -f /usr/lib64/libstdc++.so.6
ln -s /usr/lib64/libstdc++.so.6.0.28/usr/lib64/libstdc++.so.6
For those who do not understand the fourth step, you can use
strings /usr/local/gcc-9.3.0/lib64/libstdc++.so.6.0.28| grep GLIBCXX
Compare the difference between /libstdc++.so.6 before and after replacement
If you have any questions, please leave a message, we will toss together
Recommended Posts