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)
相关推荐
源远流长jerry40 分钟前
STM32之MCU和GPIO
linux·c++·stm32·单片机·嵌入式硬件
汤永红1 小时前
week2-[一维数组]最大元素
数据结构·c++·算法·信睡奥赛
Minecraft红客4 小时前
C++小游戏荒芜的城堡
c++·游戏·娱乐
scx2013100410 小时前
20250814 最小生成树和重构树总结
c++·算法·最小生成树·重构树
weixin_3077791312 小时前
VS Code配置MinGW64编译SQLite3库
开发语言·数据库·c++·vscode·算法
一瞬祈望12 小时前
Visual Studio Code 基础设置指南
vscode·编辑器
励志不掉头发的内向程序员13 小时前
STL库——string(类函数学习)
开发语言·c++
浮灯Foden15 小时前
算法-每日一题(DAY13)两数之和
开发语言·数据结构·c++·算法·leetcode·面试·散列表
淡海水16 小时前
【原理】Struct 和 Class 辨析
开发语言·c++·c#·struct·class
青草地溪水旁17 小时前
UML函数原型中stereotype的含义,有啥用?
c++·uml