系统版本:
[root@xuperior-pc gcc-10.2.0]# cat /etc/centos-release
CentOS Stream release 8
当前gcc版本
[root@xuperior-pc gcc-10.2.0]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)
下载release版本:
http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-10.2.0/
解压后进入src目录下载依赖:
[root@xuperior-pc gcc-10.2.0]# ./contrib/download_prerequisites
2021-03-27 09:21:57 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840/2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2021-03-27 09:22:14 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284/1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2021-03-27 09:22:37 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925/669925] -> "./mpc-1.0.3.tar.gz" [1]
2021-03-27 09:23:04 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291/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.
[root@xuperior-pc gcc-10.2.0]#
执行configure;参数可以直接copy 当前版本的Configured with:的参数值,修改下--prefix=/usr 安装目录就可以了;不指定该参数会默认安装到/usr/local目录下
保留你需要的参数
[root@xuperior-pc gcc-10.2.0]# ./configure --enable-bootstrap --enable-languages=c,c++,lto --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --enable-gnu-indirect-function --enable-cet --with-tune=generic
然后执行
make && make install
等待漫长的编译过程结束.............
等了很久冒出来个这玩意
/usr/include/gnu/stubs.h:7:11: fatal error: gnu/stubs-32.h: No such file or directory
7 | # include <gnu/stubs-32.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
赶紧查一下在哪里
[root@xuperior-pc gcc-10.2.0]# yum provides */stubs-32.h
Last metadata expiration check: 3 days, 1:03:31 ago on Wed 24 Mar 2021 09:44:50 AM EDT.
glibc-devel-2.28-151.el8.i686 : Object files for development using standard C libraries.
Repo : baseos
Matched from:
Filename : /usr/include/gnu/stubs-32.h
[root@xuperior-pc gcc-10.2.0]# yum install glibc-devel
安装好,再继续.....
[root@xuperior-pc gcc-10.2.0]# yum -y install glibc-devel.i686
还不行。要装64位的
ten thousand years later.......
终于编译完了。再去install。
[root@xuperior-pc gcc-10.2.0]# /usr/local/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-pc-linux-gnu
Configured with: ./configure --enable-bootstrap --enable-languages=c,c++,lto --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --enable-gnu-indirect-function --enable-cet --with-tune=generic
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
[root@xuperior-pc gcc-10.2.0]#
[root@xuperior-pc gcc-10.2.0]# /usr/local/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
Target: x86_64-pc-linux-gnu
Configured with: ./configure --enable-bootstrap --enable-languages=c,c++,lto --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --enable-gnu-indirect-function --enable-cet --with-tune=generic
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)
std对应6.0.28
[root@xuperior-pc gcc-10.2.0]# ls /usr/local/lib64 -al | grep stdc++
-rw-r--r--. 1 root root 53771084 Mar 27 22:24 libstdc++.a
-rw-r--r--. 1 root root 13362524 Mar 27 22:24 libstdc++fs.a
-rwxr-xr-x. 1 root root 905 Mar 27 22:24 libstdc++fs.la
-rwxr-xr-x. 1 root root 965 Mar 27 22:24 libstdc++.la
lrwxrwxrwx. 1 root root 19 Mar 27 22:24 libstdc++.so -> libstdc++.so.6.0.28
lrwxrwxrwx. 1 root root 19 Mar 27 22:24 libstdc++.so.6 -> libstdc++.so.6.0.28
-rwxr-xr-x. 1 root root 20941400 Mar 27 22:24 libstdc++.so.6.0.28
-rw-r--r--. 1 root root 2394 Mar 27 22:24 libstdc++.so.6.0.28-gdb.py
看下支持的std库版本如下:
[root@xuperior-pc gcc-10.2.0]# strings /usr/local/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
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.14
GLIBC_2.6
GLIBC_2.4
GLIBC_2.18
GLIBC_2.16
GLIBC_2.17
GLIBC_2.3.2
如果prefix参数指定其他目录可以自行拷贝:bin include lib lib64 libexec share到usr或者local下
编译脚本核运行的时候如果不想改默认版本请自行指定gcc
/usr/local/bin/g++
/usr/local/bin/gcc
或者临时修改环境变量
export PATH=${YOUR_DIR}/gcc-10.2.0/bin:$PATH
运行时指定动态库加载路径
export LD_LIBRARY_PATH=${YOUR_DIR}/gcc-10.2.0/lib64:$LD_LIBRARY_PATH
Done!!