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)
相关推荐
T0uken36 分钟前
【QT Quick】C++交互:QML对象操作
c++·qt·交互
寂柒1 小时前
C++——模拟实现stack和queue
开发语言·c++·算法·list
熬夜学编程的小王1 小时前
C++类与对象深度解析(一):从抽象到实践的全面入门指南
c++·git·算法
CV工程师小林1 小时前
【算法】DFS 系列之 穷举/暴搜/深搜/回溯/剪枝(下篇)
数据结构·c++·算法·leetcode·深度优先·剪枝
zh路西法2 小时前
基于opencv-C++dnn模块推理的yolov5 onnx模型
c++·图像处理·pytorch·opencv·yolo·dnn·yolov5
-指短琴长-2 小时前
BFS解决多源最短路问题_01矩阵_C++【含多源最短路问题介绍+dist数组介绍】
c++·矩阵·宽度优先
小码农<^_^>2 小时前
c++继承(下)
开发语言·c++
盒马盒马2 小时前
Redis:cpp.redis++通用接口
数据库·c++·redis
无夜_3 小时前
Prototype(原型模式)
开发语言·c++
刘好念4 小时前
[图形学]smallpt代码详解(1)
c++·计算机图形学