CentOS 7.6 编译安装最新版本GCC 9.2.0 实录

游客5ibpcdph45ep2 2019-09-17

升级 centos gcc makefile 编译 最新

最近打算用ScyllaDB做分布式数据库,但在CentOS7.6上发现GCC太老需要升级,GCC并不好编译需要很多依赖的和对应的版本,试了两天终于通过了,编译过程比较漫长朋友们需要耐心等待。以下是已经验证过可以正确编译安装的步骤给大家参考,欢迎指教!

注意:GCC是Linux的核心模块,升级可能会导致一些问题,请谨慎升级,升级之前做好备份工作。


root@xxx-xxxx ~ # cat /etc/redhat-release    # 查看当前linux版本信息
CentOS Linux release 7.6.1810 (Core) 

root@xxx-xxxx ~ # gcc -v    # 查看当前gcc版本信息
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../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
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

root@xxx-xxxx ~ # yum -y install wget bzip2 gcc gcc-c++ glibc-headers
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
base                                                                                          | 3.6 kB  00:00:00     
epel                                                                                          | 5.3 kB  00:00:00     
extras                                                                                        | 3.4 kB  00:00:00     
updates                                                                                       | 3.4 kB  00:00:00     
软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本
软件包 bzip2-1.0.6-13.el7.x86_64 已安装并且是最新版本
软件包 gcc-4.8.5-36.el7_6.2.x86_64 已安装并且是最新版本
软件包 gcc-c++-4.8.5-36.el7_6.2.x86_64 已安装并且是最新版本
软件包 glibc-headers-2.17-260.el7_6.6.x86_64 已安装并且是最新版本
无须任何处理

root@xxx-xxxx ~ # wget -c -P /opt/tmp/ https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz    # 下载安装源码压缩包
--2019-09-17 01:39:04--  https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz
正在解析主机 ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
正在连接 ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:70607648 (67M) [application/x-tar]
正在保存至: “gcc-9.2.0.tar.xz”

100%[===========================================================================>] 70,607,648   464KB/s 用时 99s    

2019-09-17 01:40:44 (696 KB/s) - 已保存 “gcc-9.2.0.tar.xz” [70607648/70607648])

root@xxx-xxxx ~ # cd /opt/tmp/
root@xxx-xxxx /opt/tmp # tar -zxvf gcc-9.2.0.tar.gz    # 解压缩源码包
......
......
gcc-9.2.0/ar-lib
gcc-9.2.0/gotools/
gcc-9.2.0/gotools/Makefile.am
gcc-9.2.0/gotools/README
gcc-9.2.0/gotools/go.1
gcc-9.2.0/gotools/gofmt.1
gcc-9.2.0/gotools/Makefile.in
gcc-9.2.0/gotools/configure
gcc-9.2.0/gotools/aclocal.m4
gcc-9.2.0/gotools/configure.ac
gcc-9.2.0/gotools/ChangeLog

root@xxx-xxxx /opt/tmp/gcc-9.2.0 # cd gcc-9.2.0
root@xxx-xxxx /opt/tmp/gcc-9.2.0 # ./contrib/download_prerequisites    #下载gmp mpfr mpc等供编译需求的依赖项
2019-09-17 01:43:33 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2019-09-17 01:43:39 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2019-09-17 01:43:43 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
2019-09-17 01:43:50 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 确定
mpfr-3.1.4.tar.bz2: 确定
mpc-1.0.3.tar.gz: 确定
isl-0.18.tar.bz2: 确定
All prerequisites downloaded successfully.

root@xxx-xxxx /opt/tmp/gcc-9.2.0 # mkdir build    #不能在source目录下configure必须在上一层的目录下
root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # cd build
root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # ../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
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
configure: WARNING: using in-tree isl, disabling version check
*** 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... no
checking for byacc... no
checking for yacc... no
checking for bison... no
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... no
checking for lex... no
checking for flex... no
checking for makeinfo... no
/opt/tmp/gcc-9.2.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... no
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@xxx-xxxx /opt/tmp/gcc-9.2.0/build # make
......
......
make  all-recursive
make[3]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm”
Making all in testsuite
make[4]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm/testsuite”
make[4]: 对“all”无需做任何事。
make[4]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm/testsuite”
make[4]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm”
true  DO=all multi-do # make
make[4]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm”
make[3]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm”
make[2]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libitm”
Checking multilib configuration for libatomic...
make[2]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
Makefile:867: warning: overriding recipe for target `all-multi'
Makefile:861: warning: ignoring old recipe for target `all-multi'
make  all-recursive
make[3]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
Makefile:867: warning: overriding recipe for target `all-multi'
Makefile:861: warning: ignoring old recipe for target `all-multi'
Making all in testsuite
make[4]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic/testsuite”
make[4]: 对“all”无需做任何事。
make[4]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic/testsuite”
make[4]: 进入目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
Makefile:867: warning: overriding recipe for target `all-multi'
Makefile:861: warning: ignoring old recipe for target `all-multi'
true  DO=all multi-do # make
make[4]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[3]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[2]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[1]: 离开目录“/opt/tmp/gcc-9.2.0/build”

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # make install
......
......
Libraries have been installed in:
   /usr/local/gcc-9.2.0/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[4]: 对“install-data-am”无需做任何事。
make[4]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[3]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[2]: 离开目录“/opt/tmp/gcc-9.2.0/build/x86_64-pc-linux-gnu/libatomic”
make[1]: 离开目录“/opt/tmp/gcc-9.2.0/build”

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # gcc -v    #查看当前gcc版本
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-9.2.0/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
目标:x86_64-pc-linux-gnu
配置为:../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
线程模型:posix
gcc 版本 9.2.0 (GCC) 

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # echo -e '\nexport PATH=/usr/local/gcc-9.2.0/bin:$PATH\n' >> /etc/profile.d/gcc.sh && source /etc/profile.d/gcc.sh
root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # ln -sv /usr/local/gcc-9.2.0/include/ /usr/include/gcc    #导出头文件
"/usr/include/gc" -> "/usr/local/gcc-9.2.0/include/"

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # ldconfig -v    #配置生效
......
......
    libkrb5support.so.0 -> libkrb5support.so.0.1
    libutempter.so.0 -> libutempter.so.1.1.6
    libxml2.so.2 -> libxml2.so.2.9.1
    libmemusage.so -> libmemusage.so
    libstdc++.so.6 -> libstdc++.so.6.0.19
    libcom_err.so.2 -> libcom_err.so.2.1
    libgmp.so.10 -> libgmp.so.10.2.0
    libsqlite3.so.0 -> libsqlite3.so.0.8.6
    libidn.so.11 -> libidn.so.11.6.11
    libncursesw.so.5 -> libncursesw.so.5.9
    libnl-genl-3.so.200 -> libnl-genl-3.so.200.23.0
    libnl-xfrm-3.so.200 -> libnl-xfrm-3.so.200.23.0
    libply.so.2 -> libply.so.2.1.0
    libnuma.so.1 -> libnuma.so.1
    libuuid.so.1 -> libuuid.so.1.3.0
    libfipscheck.so.1 -> libfipscheck.so.1.2.1
    libsnappy.so.1 -> libsnappy.so.1.1.4
    libcrypt.so.1 -> libcrypt-2.17.so
    libhandle.so.1 -> libhandle.so.1.0.3
    libestr.so.0 -> libestr.so.0.0.0
    libudev.so.1 -> libudev.so.1.6.2
/lib/sse2: (hwcap: 0x0000000004000000)
/lib64/sse2: (hwcap: 0x0000000004000000)
/lib64/tls: (hwcap: 0x8000000000000000)

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # ldconfig -p |grep gcc    #导出验证
    libgcc_s.so.1 (libc6,x86-64) => /lib64/libgcc_s.so.1

root@xxx-xxxx /opt/tmp/gcc-9.2.0/build # gcc -v    # 查看升级后的gcc版本信息,验证安装是否成功
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
目标:x86_64-pc-linux-gnu
配置为:../configure --prefix=/usr/local/gcc --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
线程模型:posix
gcc 版本 9.2.0 (GCC) 

以上内容来自我的CSDN博客:https://blog.csdn.net/RyanFang/article/details/100927373

登录 后评论
下一篇
云攻略小攻
679人浏览
2019-10-21
相关推荐
0
0
2
606