CMake Error:check_source_compiles: CXX: needs to be enabled before use.已解决

在windows中使用安装的msys2-x86_64-20240113.exe下的C:/msys64/mingw64/bin/中的g++.exe和gcc.exe出现标题中报错

经搜索有类似错误:

bash 复制代码
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)
相关推荐
月夜的风吹雨1 小时前
【封装红黑树】:深度解析map和set的底层实现
c++·set·map·封装
列逍1 小时前
深入理解 C++ 智能指针:原理、使用与避坑指南
开发语言·c++
C语言小火车2 小时前
C/C++ 指针全面解析:从基础到进阶的终极指南
c语言·开发语言·c++·指针
wefg12 小时前
【C++】特殊类设计
开发语言·c++
帅中的小灰灰3 小时前
C++编程原型设计模式
开发语言·c++
凌康ACG3 小时前
Sciter窗口间状态事件交互(四)
c++·sciter
QQ__17646198243 小时前
Vscode安装步骤(详细版)
ide·vscode·编辑器
“αβ”4 小时前
MySQL库的操作
linux·服务器·网络·数据库·c++·mysql·oracle
月夜的风吹雨4 小时前
【 C++哈希容器】:unordered_map与unordered_set深度解析
c++·哈希算法·unordered_map·unordered_set
薛定e的猫咪4 小时前
【调试技巧】vscode 四种断点调试,快速定位 bug
ide·vscode·python·bug