centos7環境升級默認的gcc-4.8.5到gcc-8.2並且升級glibc到glibc-2.28


centos7環境升級默認的gcc-4.8.5到gcc-8.2並且升級glibc到glibc-2.28


公司新做了一個圖片識別的底層sdk,這個SDK是依賴centos8的glibcxx3.4.25編譯處理的,我們的系統是centos7短時間內升級centos7代價太大,需要將centos的glibcxx升級到3.4.25來適配這個sdk的接口
glibcxx3.4.25所依托的glibc是glibc-2.28,這個可以通過啟動docker模擬的centos8系統來查看

centos7默認的 gcc 版本為 4.8.5,這個版本的gcc 無法編譯高版本的glibc 2.28

需要升級gcc到8.2版本

注意:gcc升級到9.2版本是不行的編譯的時候報錯和glibc2.28不兼容


# centos7自帶默認的glibc

# 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 軟件版本號

# 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

# 通過 docker 啟動 centos8 系統來查看glibc版本

# docker run -it --name=mycentos centos
# centos 8默認的glibc為2.28

[root@9b943b198905 /]# ls -l /usr/lib64/libstdc++.so.6
lrwxrwxrwx 1 root root 19 Jun 15  2020 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.25

[root@9b943b198905 /]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC
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
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.14
GLIBC_2.4
GLIBC_2.18
GLIBC_2.16
GLIBC_2.17
GLIBC_2.3.2
GLIBCXX_DEBUG_MESSAGE_LENGTH
GA+GLIBCXX_ASSERTIONS

[root@9b943b198905 /]# rpm -qa | grep glibc 
glibc-minimal-langpack-2.28-127.el8.x86_64
glibc-2.28-127.el8.x86_64
glibc-common-2.28-127.el8.x86_64

1.安裝gcc-8.2.0所依賴的環境

a.yum install bison -y
yum -y install wget bzip2 gcc gcc-c++ glibc-headers

b.升級GNU Make 3.82到4.2.1

wget 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 -v

c.安裝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/pip3

4.安裝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 [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.

# mkdir build    #不能在source目錄下configure必須在上一層的目錄下
# cd build
[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
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版本

[root@sz_jszx_cloud_dev01_17_58 build]# 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

# 配置生效

[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

# 導出驗證

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

5.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/

[root@sz_jszx_cloud_dev01_17_58 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 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
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]
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]
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]
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/profile

export 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

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

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

 安裝zlib 1.2.11

cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --libdir=/lib64/
make && make install

# 查看版本
strings /lib64/libz.so.1|grep ZLIB

# 刪除老版本(其實可以不刪除)
# rpm -qa | grep zlib | xargs  rpm -e --nodeps
# 這個可以刪除
# rm -f /lib64/libz.so.1.2.7

ldconfig
ll /lib64/libz.*


rm -f /usr/local/lib/libz.so.1
ln -s /lib64/libz.so.1.2.11 /usr/local/lib/libz.so.1

 報錯:
-bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8)

處理方法
vim /etc/environment

LANG=en_US.utf-8
LC_ALL=


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM