安装 gcc 9.0及以上版本
http://gcc.gnu.org/mirrors.htm
wget https://mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-9.5.0/gcc-9.5.0.tar.gz
tar zxf gcc-9.5.0.tar.gz
cd gcc-9.5.0
mkdir build
cd build
../configure --enable-languages=c,c++ --disable-multilib
如果上一步出错
configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
那么进行 ./contrib/download_prerequisites 这一步
make j4 //在编译之前需要安装 gcc 以及 g++ yum install gcc ; yum install gcc-c++
make //默认安装在 /usr/local
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
Install latest GCC from source on Centos Linux release | by Bipul Kuri | Medium
测试
这里使用 C++ 17 特性 <filesystem> 简单获取一下当前路径
#include <filesystem> //for curr path
auto currpth = std::filesystem::current_path(); myprintf("currpath :%s\n", currpth.c_str());