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

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


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)


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

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,033评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,725评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,473评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,846评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,848评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,691评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,053评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,700评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,856评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,676评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,787评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,430评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,034评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,990评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,218评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,174评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,526评论 2 343

推荐阅读更多精彩内容