https://blog.csdn.net/m0_37876242/article/details/121300805
在环境下有多个g++的时候,不(在CMakeLists.txt中显示或cmake指令执行时)指定g++的位置,cmake会自己找g++,这个g++的版本可能会是低版本的
运行cmake命令从其输出中可以看到其使用的编译器路径和版本
[root@localhost linux]# cmake ..
-- The C compiler identification is GNU 9.3.0 # c编译器版本
-- The CXX compiler identification is GNU 9.3.0 # c++编译器版本
-- Check for working C compiler: /usr/bin/cc # c编译器路径
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/bin/c++ # c++编译器路径
-- Check for working CXX compiler: /usr/local/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
指定使用的编译器的路径,使用如下方式来指定;
cmake .. -DCMAKE_CXX_COMPILER=c++编译器的绝对路径
附:如果编译器版本对了,还是出现疑似不是c++17(即c++版本不对)的问题,注意检查CMakeLists.txt
中是否有set(CMAKE_CXX_STANDARD 17)