# 升级gcc
本样例讲gcc升级到v13.2
# 编译 gmp
yum install m4
tar xvf gmp-6.2.1.tar.bz2
cd gmp-6.2.1
./configure --prefix=/usr/local/gmp
make -j4 && make install
1
2
3
4
5
2
3
4
5
# 编译 mpfr
tar xvf mpfr-4.1.0.tar.bz2
cd mpfr-4.1.0
./configure --prefix=/usr/local/mpfr --with-gmp=/usr/local/gmp
make -j4 && make install
echo "/usr/local/mpfr/lib" > /etc/ld.so.conf.d/mpfr.conf
1
2
3
4
5
2
3
4
5
# 编译 mpc
tar xvf mpc-1.2.1.tar.gz
cd mpc-1.2.1
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr
make -j4 && make install
1
2
3
4
2
3
4
# 编译 gcc
tar xvf gcc-13.2.0.tar.gz
cd gcc-13.2.0
./configure --prefix=/usr/local/gcc --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --with-mpc=/usr/local/mpc
make -j24 && make install
1
2
3
4
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/cpp /usr/bin/cpp_bak
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6_bak
mv /usr/lib64/libstdc++.so.6.0.25 /usr/lib64/libstdc++.so.6.0.25_bak # 检查是否是 libstdc++.so.6.0.25
1
2
3
4
5
6
2
3
4
5
6
# 建立软连接
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc/bin/cpp /usr/bin/cpp
ln -s /usr/local/gcc/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
ln -s /usr/local/gcc/lib64/libstdc++.so.6.0.32 /usr/lib64/libstdc++.so.6.0.32
1
2
3
4
5
6
2
3
4
5
6
# 查看最终版本
gcc -v
1