天天看點

CentOS 7.6 編譯安裝最新版本GCC 9.2.0 實錄

最近打算用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