前言c c++ 等等 需要这个编译器gcc,最近有DBA的朋友咨询RHEL7.6操作系统安装Mysql数据库时需要 高版本的GCC,研究了下发现坑不少,总结本文分享给大家
1.当前gcc版本[root@rhel76 ~]# gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapperTarget: x86_64-redhat-linuxConfigured 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-linuxThread model: posixgcc 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-multilibchecking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking target system type... x86_64-pc-linux-gnuchecking for a BSD-compatible install... /usr/bin/install -cchecking whether ln works... yeschecking whether ln -s works... yeschecking for a sed that does not truncate output... /usr/bin/sedchecking for gawk... gawkchecking for libatomic support... yeschecking for libitm support... yeschecking for libsanitizer support... yeschecking for libvtv support... yeschecking for libhsail-rt support... yeschecking for libphobos support... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking whether g++ accepts -static-libstdc++ -static-libgcc... nochecking for gnatbind... nochecking for gnatmake... nochecking whether compiler driver understands Ada... nochecking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2checking for objdir... .libschecking for the correct version of gmp.h... noconfigure: 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 specifytheir locations. Source code for these libraries can be found attheir respective hosting sites as well as athttps://gcc.gnu.org/pub/gcc/infrastructure/. See alsohttp://gcc.gnu.org/install/prerequisites.html for additional info. Ifyou obtained GMP, MPFR and/or MPC from a vendor distribution package,make sure that you have installed both the libraries and the headerfiles. 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 installmake[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.1checking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking target system type... x86_64-pc-linux-gnuchecking for a BSD-compatible install... /usr/bin/install -cchecking whether ln works... yeschecking whether ln -s works... yeschecking for a sed that does not truncate output... /usr/bin/sedchecking for gawk... gawkchecking for libatomic support... yeschecking for libitm support... yeschecking for libsanitizer support... yeschecking for libvtv support... yeschecking for libhsail-rt support... yeschecking for libphobos support... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking whether g++ accepts -static-libstdc++ -static-libgcc... nochecking for gnatbind... nochecking for gnatmake... nochecking whether compiler driver understands Ada... nochecking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2checking for objdir... .libschecking for the correct version of gmp.h... yeschecking for the correct version of mpfr.h... buggy but acceptablechecking for the correct version of mpc.h... yeschecking for the correct version of the gmp/mpfr/mpc libraries... yeschecking for isl 0.15 or later... norequired 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-debugchecking for --enable-vtable-verify... nochecking for bison... bison -ychecking for bison... bisonchecking for gm4... nochecking for gnum4... nochecking for m4... m4checking for flex... flexchecking for flex... flexchecking for makeinfo... no/root/gcc-10.1.0/missing: line 81: makeinfo: command not foundchecking for expect... nochecking for runtest... nochecking for ar... archecking for as... aschecking for dlltool... nochecking for ld... ldchecking for lipo... nochecking for nm... nmchecking for ranlib... ranlibchecking for strip... stripchecking for windres... nochecking for windmc... nochecking for objcopy... objcopychecking for objdump... objdumpchecking for otool... nochecking for readelf... readelfchecking for cc... ccchecking for c++... c++checking for gcc... gccchecking for gfortran... gfortranchecking for gccgo... nochecking for gdc... nochecking for ar... nochecking for ar... archecking for as... nochecking for as... aschecking for dlltool... nochecking for dlltool... nochecking for ld... nochecking for ld... ldchecking for lipo... nochecking for lipo... nochecking for nm... nochecking for nm... nmchecking for objcopy... nochecking for objcopy... objcopychecking for objdump... nochecking for objdump... objdumpchecking for otool... nochecking for otool... nochecking for ranlib... nochecking for ranlib... ranlibchecking for readelf... nochecking for readelf... readelfchecking for strip... nochecking for strip... stripchecking for windres... nochecking for windres... nochecking for windmc... nochecking for windmc... nochecking where to find the target ar... host toolchecking where to find the target as... host toolchecking where to find the target cc... just compiledchecking where to find the target c++... just compiledchecking where to find the target c++ for libstdc++... just compiledchecking where to find the target dlltool... host toolchecking where to find the target gcc... just compiledchecking where to find the target gfortran... host toolchecking where to find the target gccgo... host toolchecking where to find the target gdc... host toolchecking where to find the target ld... host toolchecking where to find the target lipo... host toolchecking where to find the target nm... host toolchecking where to find the target objcopy... host toolchecking where to find the target objdump... host toolchecking where to find the target otool... host toolchecking where to find the target ranlib... host toolchecking where to find the target readelf... host toolchecking where to find the target strip... host toolchecking where to find the target windres... host toolchecking where to find the target windmc... host toolchecking whether to enable maintainer-specific portions of Makefiles... noconfigure: creating ./config.statusconfig.status: creating Makefile[root@jeames007 ~]# make -j4make 时间很长,很长,耐心等待,本人编译了1个小时。所以有条件的话,在编译时,可以使用make -j8[root@jeames007 build]# make install此时GCC版本还未更新下,需要以下的操作
7.GCC版本更新mv /usr/bin/gcc /usr/bin/gcc485mv /usr/bin/g++ /usr/bin/g++485mv /usr/bin/c++ /usr/bin/c++485mv /usr/bin/cc /usr/bin/cc485ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/gccln -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/ccmv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bakln -s /usr/local/gcc-10.1.0/lib64/libstdc++.so.6.0.28 /usr/lib64/libstdc++.so.6脚本执行成功之后就可以查看当前使用的gcc版本了 查看的命令:gcc -v[root@jeames007 ~]# gcc -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/local/gcc-10.1.0/libexec/gcc/x86_64-pc-linux-gnu/10.1.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured 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.1Thread model: posixSupported LTO compression algorithms: zlibgcc version 10.1.0 (GCC) 
下载地址: Docker部署前后端分离项目的实现示例 CentOS7环境下gcc(版本10.2.0)升级详细过程 |