项目场景:
编译YouCompleteMe时,遇到C++编译器不支持C++17,导致编译失败。
问题描述
- 出错的关键日志
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:232 (message):
Your C++ compiler does NOT fully support C++17.
-- Configuring incomplete, errors occurred!
See also "/tmp/ycm_build_ym0u6oos/CMakeFiles/CMakeOutput.log".
- gcc-11.2.0 已安装并且支持C++17,但不是安装在/usr/bin/目录下
- 项目执行环境中已配置PATH优先为gcc-11.2.0的安装路径,执行c++显示的是11.2.0(正确)
- 项目执行编译时,依然显示gcc是4.8.5,所以不支持C++17
原因分析:
通过 查看cmake/CMakeCache.txt 可知,原来,CMake在构建时,通过/usr/bin/c++进行判断其版本号来判断是否支持C++17。
解决方案:
清除缓存 CMakeCache.txt,极有可能解决此问题
但最好效的方法是,执行环境中设置下CC和CXX的变量赋值
...
export CC=$(which gcc)
export CXX=$(which g++)
...