在windows中使用安装的msys2-x86_64-20240113.exe下的C:/msys64/mingw64/bin/中的g++.exe和gcc.exe出现标题中报错
经搜索有类似错误:
CMake Error at /usr/share/cmake/Modules/Internal/CheckFlagCommonConfig.cmake:58 (message):
check_compiler_flag: C: needs to be enabled before use.
有提示解决办法:
You should either check if C is enabled in the CMakeLists.txt here before using check_c_compiler_flag
, of just enable C with project("bitpit" C CXX)
at the top of the file.
也即在根CMakeLists.txt文件中的project中的工程名后添加C、CXX,分别对应C、C++编译器
如project(Test)修改为project(Test C CXX)
且应添加各指定编译器设置:
set(CMAKE_AR C:/msys64/mingw64/bin/ar.exe)
set(CMAKE_C_COMPILER C:/msys64/mingw64/bin/gcc.exe)
set(CMAKE_CXX_COMPILER C:/msys64/mingw64/bin/g++.exe)