Linux超详细gcc升级全过程

作者:IT邦德 时间:2023-10-30 03:02:41 

前言

c c++ 等等 需要这个编译器gcc,最近有DBA的朋友咨询RHEL7.6操作系统安装Mysql数据库时需要 高版本的GCC,研究了下发现坑不少,总结本文分享给大家

1.当前gcc版本


[root@rhel76 ~]# 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-36) (GCC)

从以上可以看出当前版本为4.8.5,本次我们升级到10.1.0

2.安装gcc


--下载地址:
https://mirrors.aliyun.com/gnu/gcc/gcc-10.1.0/

[root@rhel76 ~]# tar -vxf gcc-10.1.0.tar.gz
[root@rhel76 gcc-10.1.0]# mkdir build
[root@rhel76 gcc-10.1.0]# cd build/
[root@rhel76 build]# ../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libhsail-rt support... yes
checking for libphobos support... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
https://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

从日志总可以看出有如下报错,故下面每个都安装
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.

3.gmp安装


[root@jeames007 ~]# tar -vxf gmp-5.0.1.tar.bz2
[root@jeames007 ~]# cd gmp-5.0.1/
[root@jeames007 gmp-5.0.1]# ./configure --prefix=/usr/local/gmp-5.0.1
[root@jeames007 gmp-5.0.1]# make
[root@jeames007 gmp-5.0.1]# make install
make[4]: Leaving directory `/root/gmp-5.0.1'
make[3]: Leaving directory `/root/gmp-5.0.1'
make[2]: Leaving directory `/root/gmp-5.0.1'
make[1]: Leaving directory `/root/gmp-5.0.1'

4.MPFR编译


[root@jeames007 ~]# tar -vxf mpfr-3.1.5.tar.xz

[root@jeames007 ~]# cd mpfr-3.1.5/
[root@jeames007 ~]#./configure --prefix=/usr/local/mpfr-3.1.5 --with-gmp=/usr/local/gmp-5.0.1
[root@jeames007 mpfr-3.1.5]# make
[root@jeames007 mpfr-3.1.5]# make install

5.MPC编译


[root@jeames007 ~]# tar -vxf mpc-1.0.1.tar.gz
[root@jeames007 ~]# cd mpc-1.0.1
[root@jeames007 ~]# ./configure --prefix=/usr/local/mpc-1.0.1 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5
[root@jeames007 mpc-1.0.1]# make
[root@jeames007 mpc-1.0.1]# make install

6.GCC 配置


[root@rhel76 ~]# cd gcc-10.1.0
[root@rhel76 gcc-10.1.0]# cd build/
../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.1

checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libhsail-rt support... yes
checking for libphobos support... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... yes
checking for the correct version of mpfr.h... buggy but acceptable
checking for the correct version of mpc.h... yes
checking for the correct version of the gmp/mpfr/mpc libraries... yes
checking for isl 0.15 or later... no
required isl version is 0.15 or later
*** This configuration is not supported in the following subdirectories:
    gnattools gotools target-libada target-libhsail-rt target-libphobos target-zlib target-libbacktrace target-libgfortran target-libgo target-libffi target-libobjc target-liboffloadmic
   (Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... no
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... flex
checking for flex... flex
checking for makeinfo... no
/root/gcc-10.1.0/missing: line 81: makeinfo: command not found
checking for expect... no
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for otool... no
checking for readelf... readelf
checking for cc... cc
checking for c++... c++
checking for gcc... gcc
checking for gfortran... gfortran
checking for gccgo... no
checking for gdc... no
checking for ar... no
checking for ar... ar
checking for as... no
checking for as... as
checking for dlltool... no
checking for dlltool... no
checking for ld... no
checking for ld... ld
checking for lipo... no
checking for lipo... no
checking for nm... no
checking for nm... nm
checking for objcopy... no
checking for objcopy... objcopy
checking for objdump... no
checking for objdump... objdump
checking for otool... no
checking for otool... no
checking for ranlib... no
checking for ranlib... ranlib
checking for readelf... no
checking for readelf... readelf
checking for strip... no
checking for strip... strip
checking for windres... no
checking for windres... no
checking for windmc... no
checking for windmc... no
checking where to find the target ar... host tool
checking where to find the target as... host tool
checking where to find the target cc... just compiled
checking where to find the target c++... just compiled
checking where to find the target c++ for libstdc++... just compiled
checking where to find the target dlltool... host tool
checking where to find the target gcc... just compiled
checking where to find the target gfortran... host tool
checking where to find the target gccgo... host tool
checking where to find the target gdc... host tool
checking where to find the target ld... host tool
checking where to find the target lipo... host tool
checking where to find the target nm... host tool
checking where to find the target objcopy... host tool
checking where to find the target objdump... host tool
checking where to find the target otool... host tool
checking where to find the target ranlib... host tool
checking where to find the target readelf... host tool
checking where to find the target strip... host tool
checking where to find the target windres... host tool
checking where to find the target windmc... host tool
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile

[root@jeames007 ~]# make -j4
make 时间很长,很长,耐心等待,本人编译了1个小时。所以有条件的话,在编译时,可以使用make -j8

[root@jeames007 build]# make install

此时GCC版本还未更新下,需要以下的操作

7.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@jeames007 ~]# 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-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.1
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (GCC)

Linux超详细gcc升级全过程

来源:https://blog.csdn.net/weixin_41645135/article/details/121573475

标签:Linux,升级,gcc
0
投稿

猜你喜欢

  • 蓝色理想曾沐阳:不要轻易做网站

    2008-04-23 12:26:00
  • VMware workstation虚拟机兼容性问题的解决方法

    2023-11-03 10:08:24
  • 微软将于6月发布Office 2010 最低价99美元

    2010-01-16 09:24:00
  • 设置IP安全策略将木马阻杀在端口外

    2009-11-24 13:16:00
  • linux禁止ping的实现实例

    2022-09-16 17:13:56
  • WordPress支付宝集成思路及实现(非插件)

    2011-06-20 18:27:07
  • 电影服务器相关网络协议简介

    2009-01-13 16:43:00
  • 个人SMTP邮件服务器简单配置

    2008-10-14 13:45:00
  • 巨人刘伟:网游大作成功率很低 必专注征途

    2009-11-27 08:36:00
  • 中关村寻宝:中国式管理书籍为何被放在小角落?

    2009-10-23 09:44:00
  • 互联网产品中的邀请机制

    2009-11-16 12:21:00
  • 什么是SPAM?搜索引擎优化中的SPAM

    2007-10-03 13:38:00
  • DeDeCMS RSS全站静态输出的实现方法

    2011-08-20 08:28:46
  • Ubuntu Server 14.04升级Ubuntu Server 16.04

    2023-09-02 23:43:23
  • 朱则荣:控制Digg的50个网站

    2009-04-03 15:41:00
  • 淘宝客赚钱有新方法 轻松月赚千元

    2010-05-10 19:20:00
  • 设计有别 英文建站与中文建站注意的细节

    2009-02-05 16:35:00
  • CentOS下MySQL的彻底卸载的几种方法

    2023-07-15 00:24:41
  • Win2K服务器端安全设置教程(3)

    2007-12-29 09:58:00
  • 网络惊爆百度漏洞 fck编辑器成最大祸首

    2010-07-23 19:52:00
  • asp之家 网站运营 m.aspxhome.com