大部分教程是直接用make install,但这样会把系统的环境干掉

标准的做法是source到rh的devtoolset。

开始安装

在系统内安装存储库

yum install centos-release-scl

安装gcc10

yum install  devtoolset-10-gcc -y

使用

scl enable devtoolset-10 bash

只要在这个 bash shell 中(不键入 exit),您的环境就被配置为使用 GNU GCC 10,并且您可以使用 make、cmake 来使用这个较新版本编译您的项目。

故障排查

找不到stdarg.h

find /usr/include -iname "stdarg.h"

系统默认的stdarg在这里,但是使用make install导致toolset变了,默认搜索路径可能不一样。

source /opt/rh/devtoolset-10/enable
gcc -xc -E -v /dev/null

得到COMPILER_PATH
export COMPILER_PATH=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/:/opt/rh/devtoolset-10/root/usr/libexec/^Cc/x86_64-redhat-linux/10/:/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/:/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/
然后改Makefile


参考:
How to install new gcc and development tools under CentOS 7

最后修改:2023 年 06 月 22 日
如果觉得我的文章对你有用,请随意赞赏