网址导航 在线音乐 免费电影 美女图片 笑话漫画 免费代理 电视影视 小说阅读

 找回密码
 注册
搜索
查看: 2469|回复: 2

centos7环境升级默认的gcc-4.8.5到gcc-8.2并且升级glibc到glibc-2.28

[复制链接]
winnercn 发表于 2022-3-18 11:47:23 | 显示全部楼层 |阅读模式
1、 查看glibc 软件版本号
# rpm -qa | grep glibc
glibc-2.17-307.el7.1.x86_64
glibc-devel-2.17-307.el7.1.x86_64
glibc-2.17-307.el7.1.i686
glibc-common-2.17-307.el7.1.x86_64
glibc-headers-2.17-307.el7.1.x86_64
2、安装gcc-8.2.0所依赖的环境
  1. yum install bison -y
  2. yum -y install wget bzip2 gcc gcc-c++ glibc-headers
复制代码
3、升级GNU Make 3.82到4.2.1
  1. wget http://ftp.gnu.org/gnu/make/make-4.2.1.tar.gz
  2. tar -zxvf make-4.2.1.tar.gz
  3. cd make-4.2.1
  4. mkdir build
  5. cd build
  6. ../configure --prefix=/usr/local/make && make && make install
  7. export PATH=/usr/local/make/bin:$PATH
  8. ln -s /usr/local/make/bin/make /usr/local/make/bin/gmake
  9. make -v
复制代码
4、安装python3.8版本
  1. wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
  2. xz -d Python-3.8.0.tar.xz
  3. tar xf Python-3.8.0.tar
  4. cd Python-3.8.0
  5. ./configure --prefix=/usr/local/python3
  6. make -j 4 && make install
  7. ln -s /usr/local/python3/bin/python3 /usr/bin/python3
  8. ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
复制代码
5、安装gcc8.2.0
centos7.8编译安装gcc9.2
  1. # wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
  2. # tar xf gcc-9.2.0.tar.gz
  3. # cd gcc-9.2.0
  4. # ./contrib/download_prerequisites    #下载gmp mpfr mpc等供编译需求的依赖项
  5. 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]
  6. 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]
  7. 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]
  8. 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]
  9. gmp-6.1.0.tar.bz2: 确定
  10. mpfr-3.1.4.tar.bz2: 确定
  11. mpc-1.0.3.tar.gz: 确定
  12. isl-0.18.tar.bz2: 确定
  13. All prerequisites downloaded successfully.

  14. # mkdir build    #不能在source目录下configure必须在上一层的目录下
  15. # cd build
  16. [root@sz_jszx_cloud_dev01_17_58 build]# ../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
  17. checking build system type... x86_64-pc-linux-gnu
  18. checking host system type... x86_64-pc-linux-gnu
  19. checking target system type... x86_64-pc-linux-gnu
  20. checking for a BSD-compatible install... /usr/bin/install -c
  21. checking whether ln works... yes
  22. checking whether ln -s works... yes
  23. checking for a sed that does not truncate output... /usr/bin/sed
  24. checking for gawk... gawk
  25. checking for libatomic support... yes
  26. checking for libitm support... yes
  27. checking for libsanitizer support... yes
  28. checking for libvtv support... yes
  29. checking for libhsail-rt support... yes
  30. checking for libphobos support... yes
  31. checking for gcc... gcc
  32. checking whether the C compiler works... yes
  33. checking for C compiler default output file name... a.out
  34. checking for suffix of executables...
  35. checking whether we are cross compiling... no
  36. checking for suffix of object files... o
  37. checking whether we are using the GNU C compiler... yes
  38. checking whether gcc accepts -g... yes
  39. checking for gcc option to accept ISO C89... none needed
  40. checking for g++... g++
  41. checking whether we are using the GNU C++ compiler... yes
  42. checking whether g++ accepts -g... yes
  43. checking whether g++ accepts -static-libstdc++ -static-libgcc... no
  44. checking for gnatbind... no
  45. checking for gnatmake... no
  46. checking whether compiler driver understands Ada... no
  47. checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
  48. checking for objdir... .libs
  49. configure: WARNING: using in-tree isl, disabling version check
  50. *** This configuration is not supported in the following subdirectories:
  51.      gnattools gotools target-libada target-libhsail-rt target-libphobos target-zlib target-libbacktrace target-libgfortran target-libgo target-libffi target-libobjc target-liboffloadmic
  52.     (Any other directories should still work fine.)
  53. checking for default BUILD_CONFIG... bootstrap-debug
  54. checking for --enable-vtable-verify... no
  55. checking for bison... bison -y
  56. checking for bison... bison
  57. checking for gm4... no
  58. checking for gnum4... no
  59. checking for m4... m4
  60. checking for flex... no
  61. checking for lex... no
  62. checking for flex... no
  63. checking for makeinfo... no
  64. /usr/local/gcc-9.2.0/missing: line 81: makeinfo: command not found
  65. checking for expect... no
  66. checking for runtest... no
  67. checking for ar... ar
  68. checking for as... as
  69. checking for dlltool... no
  70. checking for ld... ld
  71. checking for lipo... no
  72. checking for nm... nm
  73. checking for ranlib... ranlib
  74. checking for strip... strip
  75. checking for windres... no
  76. checking for windmc... no
  77. checking for objcopy... objcopy
  78. checking for objdump... objdump
  79. checking for otool... no
  80. checking for readelf... readelf
  81. checking for cc... cc
  82. checking for c++... c++
  83. checking for gcc... gcc
  84. checking for gfortran... no
  85. checking for gccgo... no
  86. checking for gdc... no
  87. checking for ar... no
  88. checking for ar... ar
  89. checking for as... no
  90. checking for as... as
  91. checking for dlltool... no
  92. checking for dlltool... no
  93. checking for ld... no
  94. checking for ld... ld
  95. checking for lipo... no
  96. checking for lipo... no
  97. checking for nm... no
  98. checking for nm... nm
  99. checking for objcopy... no
  100. checking for objcopy... objcopy
  101. checking for objdump... no
  102. checking for objdump... objdump
  103. checking for otool... no
  104. checking for otool... no
  105. checking for ranlib... no
  106. checking for ranlib... ranlib
  107. checking for readelf... no
  108. checking for readelf... readelf
  109. checking for strip... no
  110. checking for strip... strip
  111. checking for windres... no
  112. checking for windres... no
  113. checking for windmc... no
  114. checking for windmc... no
  115. checking where to find the target ar... host tool
  116. checking where to find the target as... host tool
  117. checking where to find the target cc... just compiled
  118. checking where to find the target c++... just compiled
  119. checking where to find the target c++ for libstdc++... just compiled
  120. checking where to find the target dlltool... host tool
  121. checking where to find the target gcc... just compiled
  122. checking where to find the target gfortran... host tool
  123. checking where to find the target gccgo... host tool
  124. checking where to find the target gdc... host tool
  125. checking where to find the target ld... host tool
  126. checking where to find the target lipo... host tool
  127. checking where to find the target nm... host tool
  128. checking where to find the target objcopy... host tool
  129. checking where to find the target objdump... host tool
  130. checking where to find the target otool... host tool
  131. checking where to find the target ranlib... host tool
  132. checking where to find the target readelf... host tool
  133. checking where to find the target strip... host tool
  134. checking where to find the target windres... host tool
  135. checking where to find the target windmc... host tool
  136. checking whether to enable maintainer-specific portions of Makefiles... no
  137. configure: creating ./config.status
  138. config.status: creating Makefile
复制代码
# 多核cpu编译,否则时间可能超过3个小时
  1. # make -j 4 && make install
复制代码
# 加入环境变量
  1. # echo -e '\nexport PATH=/usr/local/gcc-9.2.0/bin:$PATH\n' >> /etc/profile.d/gcc.sh && source /etc/profile.d/gcc.sh
复制代码
# 查看gcc版本
  1. [root@sz_jszx_cloud_dev01_17_58 build]# gcc -v
  2. Using built-in specs.
  3. COLLECT_GCC=gcc
  4. COLLECT_LTO_WRAPPER=/usr/local/gcc-9.2.0/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
  5. Target: x86_64-pc-linux-gnu
  6. Configured with: ../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
  7. Thread model: posix
  8. gcc version 9.2.0 (GCC)
复制代码
# 导出头文件
  1. # ln -sv /usr/local/gcc-9.2.0/include/ /usr/include/gcc
复制代码
# 配置生效
[root@sz_jszx_cloud_dev01_17_58 build]# ldconfig -v
ldconfig: Can't stat /libx32: No such file or directory
ldconfig: Path `/usr/lib' given more than once
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
/usr/lib64//bind9-export:
        libisccfg-export.so.160 -> libisccfg-export.so.160.2.1
        libisc-export.so.169 -> libisc-export.so.169.0.3
        libirs-export.so.160 -> libirs-export.so.160.0.5
        libdns-export.so.1102 -> libdns-export.so.1102.1.2
/usr/lib64/mysql:
        libmysqlclient.so.21 -> libmysqlclient.so.21.1.22
        libmysqlclient.so.18 -> libmysqlclient_r.so.18.1.0
/lib:
/lib64:
        liblzf.so.1 -> liblzf.so.1.0.0
        libicuuc.so.65 -> libicuuc.so.65.1
        libicutu.so.65 -> libicutu.so.65.1
        libicutest.so.65 -> libicutest.so.65.1
        libicuio.so.65 -> libicuio.so.65.1
        libicui18n.so.65 -> libicui18n.so.65.1
        libicudata.so.65 -> libicudata.so.65.1
        libkadm5srv_mit.so.11 -> libkadm5srv_mit.so.11.0


 楼主| winnercn 发表于 2022-3-18 11:53:05 | 显示全部楼层
本帖最后由 winnercn 于 2022-3-18 16:45 编辑

# 导出验证
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

# ldconfig -p |grep gcc
libgcc_s.so.1 (libc6,x86-64) => /lib64/libgcc_s.so.1

gcc9.2版本太新和glibc-2.28不兼容,更换为 gcc-8.2.0,编译过程和gcc9.2一样
获取 gcc-8.2.0版本源码
  1. wget http://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

  2. tar xf gcc-8.2.0.tar.gz
  3. cd gcc-8.2.0/
复制代码
  1. [root@sz_jszx_cloud_dev01_17_58 gcc-8.2.0]# ./contrib/download_prerequisites
  2. 2021-02-26 17:01:45 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
  3. 2021-02-26 17:03:08 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
  4. 2021-02-26 17:04:00 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
  5. 2021-02-26 17:06:35 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291] -> "./isl-0.18.tar.bz2" [1]
  6. gmp-6.1.0.tar.bz2: OK
  7. mpfr-3.1.4.tar.bz2: OK
  8. mpc-1.0.3.tar.gz: OK
  9. isl-0.18.tar.bz2: OK
  10. All prerequisites downloaded successfully.
  11. # mkdir build
  12. # cd build
复制代码
# 预编译
  1. # ../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
复制代码
# 开启多线程编辑加快速度
  1. make -j 4 && make install
复制代码
修改环境变量,使得gcc-8.2.0为默认的gcc
  1. # vim /etc/profile
复制代码
  1. export PATH=/usr/local/gcc-8.2.0/bin${PATH:+:${PATH}}
  2. export MANPATH=/usr/local/gcc-8.2.0/share/man:${MANPATH}
  3. export INFOPATH=/usr/local/gcc-8.2.0/share/info${INFOPATH:+:${INFOPATH}}
  4. export LD_LIBRARY_PATH=/usr/local/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/7.2.0:/usr/local/gcc-8.2.0/lib64:/usr/local/gcc-8.2.0/lib/gcc/x86_64-pc-linux-gnu/8.2.0/plugin${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
复制代码
使其生效:
. /etc/profile

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 8.2.0 (GCC)

#导出头文件
# ln -sv /usr/local/gcc-8.2.0/include/ /usr/include/gcc

[root@sz_jszx_cloud_dev01_17_58 build]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-8.2.0/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 8.2.0 (GCC)


[opsadmin@sz_jszx_cloud_dev01_17_58 ~]$ strings /lib64/libc.so.6 | grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
...

回复

使用道具 举报

 楼主| winnercn 发表于 2022-3-18 11:54:39 | 显示全部楼层
6、编译glibc2.28
  1. # wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
复制代码
编译
# 编译时间较长,开启screen避免编译中断
# screen -S glibc
# tar -xf glibc-2.28.tar.gz
# cd glibc-2.28
# mkdir build
# cd build
# 预编译
# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
# 多线程编译,加快编译速度
# make -j 4 && make  install

这个报错可以不用理会
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /usr/local/src/glibc-2.28/build/
/usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
Execution of gcc -B/usr/bin/ failed!
The script has found some problems with your installation!
Please read the FAQ and the README file and check the following:
- Did you change the gcc specs file (necessary after upgrading from
  Linux libc5)?
- Are there any symbolic links of the form libXXX.so to old libraries?
  Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,
  libm.so should point to the newly installed glibc file - and there should be
  only one such link (check e.g. /lib and /usr/lib)
You should restart this script from your build directory after you've
fixed all problems!
Btw. the script doesn't work if you're installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory '/usr/local/src/glibc-2.28'
make: *** [Makefile:12: install] Error 2
# 验证是否成功
[root@sz_jszx_cloud_dev01_17_58 build]# strings /usr/local/gcc-8.2.0/lib64/libstdc++.so.6 | grep GLIBCXX_
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25


[root@sz_jszx_cloud_dev01_17_58 build]#  strings /lib64/libc.so.6 | grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_2.18
GLIBC_2.22
GLIBC_2.23
GLIBC_2.24
GLIBC_2.25
GLIBC_2.26
GLIBC_2.27
GLIBC_2.28

[root@sz_jszx_cloud_dev01_17_58 local]# ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表