gcc升级

  1. 当前gcc版本
[root@localhost ~]# gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
# 版本号
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
  1. 安装gcc
https://mirrors.aliyun.com/gnu/gcc/gcc-10.1.0/

wget https://mirrors.aliyun.com/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.gz
[root@localhost gcc_bag]# ls
gcc-10.1.0.tar.gz
[root@localhost gcc_bag]# tar -zxvf gcc-10.1.0.tar.gz
[root@localhost gcc_bag]# ls
gcc-10.1.0.tar.gz gcc-10.1.0
[root@localhost gcc_bag]# cd gcc-10.1.0
[root@localhost gcc-10.1.0]# mkdir build/
[root@localhost gcc-10.1.0]# cd build/
[root@localhost build]#../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib

image

上图中的链接很重要[https://gcc.gnu.org/pub/gcc/infrastructure/]

  1. 解决上面的问题--安装gmp
[root@localhost gmpp]# wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2

Wget 出现问题之后

ERROR: cannot verify xxx certificate, issued by ‘/C=US/O=Let’s Encrypt/CN=R3’:use --no-check-certif

如何解压*.tar.bz2文件

[root@localhost gmpp]# cd gmp-6.2.1
[root@localhost gmp-6.2.1]# ./configure --prefix=/usr/local/gmp-6.2.1
......
checking whether sscanf needs writable input... no
checking for struct pst_processor.psp_iticksperclktick... no
# 报错
checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).

ubuntu下安装gmp遇到 configure:error:no usable m4 in$path or /user/5bin解决方案

然后

config.status: executing libtool commands
configure: summary of build options:

  Version:           GNU MP 6.2.1
  Host type:         kabylake-pc-linux-gnu
  ABI:               64
  Install prefix:    /usr/local/gmp-6.2.1
  Compiler:          gcc -std=gnu99
  Static libraries:  yes
  Shared libraries:  yes

第4步第5步的安装包也在 ----上面很重要的链接

  1. MPFR编译
[root@localhost gmpp]# tar -jvxf mpfr-4.1.0.tar.bz2

[root@localhost gmpp]# cd mpfr-4.1.0/
[root@localhost mpfr-4.1.0]#./configure --prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
[root@localhost mpfr-4.1.0]# make
[root@localhost mpfr-4.1.0]# make install
  1. MPC编译
[root@localhost gmpp]# tar -zvxf mpc-1.2.1.tar.gz
[root@localhost gmpp]# cd mpc-1.2.1
[root@localhost mpc-1.2.1]# ./configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
[root@localhost mpc-1.2.1]# make
[root@localhost mpc-1.2.1]# make install
  1. GCC 配置
[root@localhost gcc_bag]# ls
gcc-10.1.0  gcc-10.1.0.tar.gz

[root@localhost gcc_bag]# cd gcc-10.1.0
[root@localhost gcc-10.1.0]# cd build

[root@localhost build]# ../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1

[root@localhost build]# cd ../


# 编译  这里执行完make -j4 会报一个错误 见下面
[root@localhost gcc-10.1.0]# make -j4 # 时间很长很长 耐心等待 也可以使用make -j8
[root@localhost gcc-10.1.0]# make install

image

error while loading shared libraries: libmpfr.so.6: cannot open shared object file

[再执行makemake install 此时需要的时间很长很长,耐心等待]

  1. GCC版本更新
mv /usr/bin/gcc /usr/bin/gcc485
mv /usr/bin/g++ /usr/bin/g++485
mv /usr/bin/c++ /usr/bin/c++485
mv /usr/bin/cc /usr/bin/cc485


ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-10.1.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-10.1.0/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/cc


mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s /usr/local/gcc-10.1.0/lib64/libstdc++.so.6.0.28 /usr/lib64/libstdc++.so.6


脚本执行成功之后就可以查看当前使用的gcc版本了  查看的命令:gcc -v

[root@localhost gcc-10.1.0]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC) 

posted @ 2022-05-17 22:23  流年中渲染了微笑  阅读(513)  评论(2编辑  收藏  举报