winnercn 发表于 2022-3-18 11:47:23

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

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_642、安装gcc-8.2.0所依赖的环境yum install bison -y
yum -y install wget bzip2 gcc gcc-c++ glibc-headers3、升级GNU Make 3.82到4.2.1wget http://ftp.gnu.org/gnu/make/make-4.2.1.tar.gz
tar -zxvf make-4.2.1.tar.gz
cd make-4.2.1
mkdir build
cd build
../configure --prefix=/usr/local/make && make && make install
export PATH=/usr/local/make/bin:$PATH
ln -s /usr/local/make/bin/make /usr/local/make/bin/gmake
make -v4、安装python3.8版本wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
xz -d Python-3.8.0.tar.xz
tar xf Python-3.8.0.tar
cd Python-3.8.0
./configure --prefix=/usr/local/python3
make -j 4 && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip35、安装gcc8.2.0
centos7.8编译安装gcc9.2# wget https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
# tar xf gcc-9.2.0.tar.gz
# cd 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 -> "./gmp-6.1.0.tar.bz2"
2019-09-17 01:43:39 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 -> "./mpfr-3.1.4.tar.bz2"
2019-09-17 01:43:43 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz -> "./mpc-1.0.3.tar.gz"
2019-09-17 01:43:50 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 -> "./isl-0.18.tar.bz2"
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.

# mkdir build    #不能在source目录下configure必须在上一层的目录下
# cd build
# ../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-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... bison -y
checking for bison... bison
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
/usr/local/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# 多核cpu编译,否则时间可能超过3个小时# make -j 4 && make install# 加入环境变量# 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版本# gcc -v
Using built-in 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
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-9.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 9.2.0 (GCC)# 导出头文件# ln -sv /usr/local/gcc-9.2.0/include/ /usr/include/gcc
# 配置生效
# 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版本源码wget http://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

tar xf gcc-8.2.0.tar.gz
cd gcc-8.2.0/# ./contrib/download_prerequisites
2021-02-26 17:01:45 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 -> "./gmp-6.1.0.tar.bz2"
2021-02-26 17:03:08 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 -> "./mpfr-3.1.4.tar.bz2"
2021-02-26 17:04:00 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz -> "./mpc-1.0.3.tar.gz"
2021-02-26 17:06:35 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 -> "./isl-0.18.tar.bz2"
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.
# mkdir build
# cd build# 预编译# ../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib
# 开启多线程编辑加快速度make -j 4 && make install
修改环境变量,使得gcc-8.2.0为默认的gcc# vim /etc/profileexport PATH=/usr/local/gcc-8.2.0/bin${PATH:+:${PATH}}
export MANPATH=/usr/local/gcc-8.2.0/share/man:${MANPATH}
export INFOPATH=/usr/local/gcc-8.2.0/share/info${INFOPATH:+:${INFOPATH}}
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

# 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)


$ 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# 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 && makeinstall

这个报错可以不用理会
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: *** Error 1
make: Leaving directory '/usr/local/src/glibc-2.28'
make: *** Error 2

# 验证是否成功
# 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


#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

# 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.

页: [1]
查看完整版本: centos7环境升级默认的gcc-4.8.5到gcc-8.2并且升级glibc到glibc-2.28