node运行的时候报了以下几个错误,查阅了不少资料,原因主要是与系统中安装的 glibc 和 libstdc++ 版本过低有关,导致无法满足 Node.js 运行所需的库版本要求。折腾半天成功解决,这里记录一下我的处理过程
node -v
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
解决办法:更新glibc和libstdc++
1、更新glibc
wget https://ftp.gnu.org/gnu/glibc/glibc-2.30.tar.gz
tar xf glibc-2.30.tar.gz
cd glibc-2.30
mkdir build
cd build/
../configure --prefix=/usr --disable-profile --enable-add-ons --with-binutils=/usr/bin
出现如下报错
configure: error:
*** These critical programs are missing or too old: make bison compiler
*** Check the INSTALL file for required versions.
安装bison、升级gcc、make
安装bison
yum -y install bison
bison --version
bison (GNU Bison) 3.0.4
Written by Robert Corbett and Richard Stallman.
Copyright (C) 2015 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.
升级gcc
##查看现有版本
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 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.
下载gcc源码包
https://mirror.marwan.ma/gcc/releases/gcc-12.1.0/gcc-12.1.0.tar.gz
tar xf gcc-12.1.0.tar.gz -C /usr/local/
##查看gcc需要的依赖
vim /usr/local/gcc-12.1.0/contrib/download_prerequisites
下面4个包就是gcc需要的依赖
##下载依赖
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
wgte https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2
##解压
tar xf gmp-6.2.1.tar.bz2 -C /usr/local/gcc-12.1.0/
tar xf mpfr-4.1.0.tar.bz2 -C /usr/local/gcc-12.1.0/
tar xf mpc-1.2.1.tar.gz -C /usr/local/gcc-12.1.0/
tar xf isl-0.24.tar.bz2 -C /usr/local/gcc-12.1.0/
##建立软连接
cd /usr/local/gcc-12.1.0/
ln -sf gmp-6.2.1 gmp
ln -sf mpfr-4.1.0 mpfr
ln -sf mpc-1.2.1 mpc
ln -sf isl-0.24 isl
编译安装gcc
cd /usr/local/gcc-12.1.0/
mkdir build
cd build
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
##这里时间较长,我的是80核的,用了差不多90分钟
make -j80 && make install
##完成之后建立软连接
mv /usr/bin/gcc /usr/local/gcc.bak
ln -s /usr/local/bin/gcc /usr/bin/gcc
查看升级后的gcc
gcc --version
gcc (GCC) 12.1.0
Copyright (C) 2022 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.
接下来继续升级make
##查看现有版本
make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar xf make-4.3.tar.gz
cd make-4.3
./configure --prefix=/usr/local/make
make
make install
cd /usr/bin/
mv make make.bak
ln -s /usr/local/make/bin/make /usr/bin/make
查看升级后的make版本
make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
继续更新glibc
cd glibc-2.28/build/
../configure --prefix=/usr --disable-profile --enable-add-ons --with-binutils=/usr/bin
make && make install
继续报错,如下
../sysdeps/nptl/pthread.h:744:47: error: argument 1 of type ‘struct __jmp_buf_tag *’ declared as a pointer [-Werror=array-parameter=]
744 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from ../include/setjmp.h:2,
from ../nptl/descr.h:24:
../setjmp/setjmp.h:54:46: note: previously declared as an array ‘struct __jmp_buf_tag[1]’
54 | extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [../Makerules:287: /root/glibc-2.28/build/tcb-offsets.h] Error 1
make[2]: Leaving directory '/root/glibc-2.28/csu'
make[1]: *** [Makefile:258: csu/subdir_lib] Error 2
make[1]: Leaving directory '/root/glibc-2.28'
make: *** [Makefile:9: all] Error 2
解决办法
##清楚之前的构建文件
make distclean
##添加CFLAGS="-Wno-error"
CFLAGS="-Wno-error" ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make && make install
然后还是提示错误
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
75 | # error "glibc cannot be compiled without optimization"
| ^~~~~
In file included from ../include/pthread.h:1,
from ../nptl/../nptl_db/thread_db.h:25,
from ../nptl/descr.h:32,
from ../sysdeps/x86_64/nptl/tls.h:130,
from ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:24,
from <stdin>:1:
../sysdeps/nptl/pthread.h:744:47: warning: argument 1 of type ‘struct __jmp_buf_tag *’ declared as a pointer [-Warray-parameter=]
744 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from ../include/setjmp.h:2,
from ../nptl/descr.h:24:
../setjmp/setjmp.h:54:46: note: previously declared as an array ‘struct __jmp_buf_tag[1]’
54 | extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
make[2]: *** [../Makerules:287: /root/glibc-2.28/build/tcb-offsets.h] Error 1
make[2]: Leaving directory '/root/glibc-2.28/csu'
make[1]: *** [Makefile:258: csu/subdir_lib] Error 2
make[1]: Leaving directory '/root/glibc-2.28'
make: *** [Makefile:9: all] Error 2
添加 -O2 解决优化问题优化
make distclean
CFLAGS="-Wno-error -O2" ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make && make install
使用node -v看一下
node -v
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
接下来继续解决libstdc++
##查看系统版本
strings /usr/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_DEBUG_MESSAGE_LENGTH
strings /usr/lib64/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_TM_1
ls -l /usr/lib64/libstdc*
lrwxrwxrwx. 1 root root 19 Feb 16 15:52 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
-rwxr-xr-x. 1 root root 995840 Sep 30 2020 /usr/lib64/libstdc++.so.6.0.19
目前用的是6.0.19,没有CXXABI_1.3.9、GLIBCXX_3.4.20、GLIBCXX_3.4.21
进入前面编译gcc的输入目录
cd /usr/local/gcc-12.1.0/build/
查找编译生成libstdc++.so库文件
find ./ -name libstdc++.so*
##拷贝libstdc++.so.6.0.30库文件到lib64目录
cp ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.30 /usr/lib64/
创建软链接
cd /usr/lib64/
##删除原来的文件
rm -rf libstdc++.so.6
##软连接
ln -s libstdc++.so.6.0.30 libstdc++.so.6
ll libstdc*
lrwxrwxrwx. 1 root root 19 Feb 16 15:52 libstdc++.so.6 -> libstdc++.so.6.0.30
-rwxr-xr-x. 1 root root 995840 Sep 30 2020 libstdc++.so.6.0.19
-rwxr-xr-x. 1 root root 14981728 Feb 16 15:51 libstdc++.so.6.0.30
再次使用node,搞定
node -v
v18.20.6