在nodejs源码编译时用到了gcc升级,由于源码使用到了c++,gcc版本太低,大于6.3即可
[root@baidu1 node-v12.18.2]# ./configure
WARNING: C++ compiler (CXX=g++, 4.8.5) too old, need g++ 6.3.0 or clang++ 8.0.0
WARNING: warnings were emitted in the configure phase
INFO: configure completed successfully
[root@baidu1 node-v12.18.2]# gcc -v
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
gcc下载地址http://ftp.gnu.org/gnu/gcc/,可以找到任意版本的.tar.gz
[root@baidu1 node-v12.18.2]# cd /usr/local/
#下载gcc安装包
[root@baidu1 local]# wget http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz
--2020-07-08 13:49:37-- http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 108377377 (103M) [application/x-gzip]
...
[root@baidu1 local]# ls
bin etc games gcc-7.1.0.tar.gz include lib lib64 libexec sbin share src
[root@baidu1 local]# tar -zxvf gcc-7.1.0.tar.gz
root@baidu1 local]# cd gcc-7.1.0/
#执行gcc给出的shell,它会去下载所需4个依赖包
[root@baidu1 gcc-7.1.0]# vi ./contrib/download_prerequisites
...
gmp='gmp-6.1.0.tar.bz2'
mpfr='mpfr-3.1.4.tar.bz2'
mpc='mpc-1.0.3.tar.gz'
isl='isl-0.16.1.tar.bz2'
base_url='ftp://gcc.gnu.org/pub/gcc/infrastructure/'
...
#他们的URL分别是
#ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
#ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
#ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
#ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
[root@baidu1 gcc-7.1.0]# ./contrib/download_prerequisites
#执行后会比较慢,担心卡住可以再开个tab查看进程,它是用的wget下载
[wang@baidu1 ~]$ ps -ef |grep wget
root 3129 3126 0 13:58 pts/0 00:00:00 wget --no-verbose -O ./isl-0.16.1.tar.bz2 ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
wang 3143 3016 0 13:58 pts/1 00:00:00 grep --color=auto wget
#这里的isl-0.16.1.tar.bz2与shell对应
#如果执行一半给退了,可以根据报错信息删掉
[root@baidu1 gcc-7.1.0]# ./contrib/download_prerequisites
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: FAILED
sha512sum: WARNING: 1 computed checksum did NOT match
error: Cannot download mpc-1.0.3.tar.gz from ftp://gcc.gnu.org/pub/gcc/infrastructure/
[root@baidu1 gcc-7.1.0]# rm -rf mpc-1.0.3.tar.gz
#还有可能会对包的校验失败,不过不碍事,不放心可以去上面的地址自己下载上传
error: Cannot verify integrity of possibly corrupted file isl-0.16.1.tar.bz2
1)编译gmp-6.1.0.tar.bz2
[root@baidu1 gcc-7.1.0]# cd gmp-6.1.0
[root@baidu1 gmp-6.1.0]# ./configure --prefix=/usr/local/gmp
[root@baidu1 gmp-6.1.0]# make && make install
如果在执行./configure --prefix=/usr/local/gmp报错,checking for suitable m4... configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).说明没有m4依赖包,执行yum install m4
2)编译mpfr-3.1.4.tar.bz2
[root@baidu1 gcc-7.1.0]# cd mpfr-3.1.4/
[root@baidu1 mpfr-3.1.4]# ./configure --prefix=/usr/local/mpfr
[root@baidu1 mpfr-3.1.4]# make && make install
如果在执行./configure --prefix=/usr/local/mpfr 报错,
checking for library containing clock_gettime... none required
checking for gmp.h... no
configure: error: gmp.h can't be found, or is unusable.
安装yum install gmp-devel.x86_64包
3)编译mpc-1.0.3.tar.gz
[root@baidu1 gcc-7.1.0]# cd mpc-1.0.3
[root@baidu1 mpc-1.0.3]# ./configure --prefix=/usr/local/mpc
[root@baidu1 mpc-1.0.3]# make && make install
如果在执行./configure --prefix=/usr/local/mpc报错,
checking for MPFR... no
configure: error: libmpfr not found or uses a different ABI (including static vs shared).
安装yum install mpfr-devel.x86_64包
4)编译isl-0.16.1.tar.bz2
[root@baidu1 gcc-7.1.0]# cd isl-0.16.1
[root@baidu1 isl-0.16.1]# ./configure --prefix=/usr/local/isl
[root@baidu1 isl-0.16.1]# make && make install
未完成
参考:https://blog.csdn.net/weixin_41010198/article/details/106780572