CentOS6.4安装swoole4.2报错:error: #error "GCC 4.8 or later required.
参考 https://blog.csdn.net/qq_24849765/article/details/75893393 安装GCC7.1
但是安装完成后还是有点问题,这里做个完整的记录
> cd /usr/local/src > wget http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.bz2 > tar -jxvf gcc-7.1.0.tar.bz2 > cd gcc-7.1.0 > ./contrib/download_prerequisites > mkdir gcc-temp > ./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib #编译超级慢 > make -j4 > make install
替换原来的gcc版本
> update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/x86_64-pc-linux-gnu-gcc 40 > mv /usr/bin/gcc /usr/bin/gcc.bak > ln -s /usr/local/bin/x86_64-pc-linux-gnu-gcc /usr/bin/gcc
安装结束后,可以安装swoole了,但是查询时报错
> php -m | grep swoole PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/swoole.so' - /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/swoole.so) in Unknown on line 0
但是查看gcc版本确实是7.1
> gcc -v COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper 目标:x86_64-pc-linux-gnu 配置为:./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib 线程模型:posix gcc 版本 7.1.0 (GCC)
查看gcc包确实缺少GLIBCXX_3.4.20
> strings /usr/lib64/libstdc++.so.6 | grep GLIBC
既然说是 /usr/lib64/libstdc++.so.6 下面缺少这个,那就用下载的源码包重建一下软链
> cp /usr/local/src/gcc-7.1.0/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.23 /usr/lib64 > cd /usr/lib64 > mv libstdc++.so.6.0.13 libstdc++.so.6.0.13.bak > ln -s libstdc++.so.6.0.23 libstdc++.so.6
运行 strings /usr/lib64/libstdc++.so.6 | grep GLIBC 再次查看
.... GLIBCXX_3.4.18 GLIBCXX_3.4.19 GLIBCXX_3.4.20 GLIBCXX_3.4.21 GLIBCXX_3.4.22 GLIBCXX_3.4.23 ...
再次运行php --ri swoole | grep Version
显示
Version => 4.2.2
说明成功了