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)
相关推荐
王老师青少年编程12 分钟前
2024年3月GESP真题及题解(C++八级): 接竹竿
c++·题解·真题·gesp·csp·八级·接竹竿
偷星星的贼1114 分钟前
C++中的访问者模式实战
开发语言·c++·算法
雾岛听蓝27 分钟前
红黑树深度解析:设计原理与实现逻辑
c++
gjxDaniel33 分钟前
A+B问题天堂版
c++·算法·字符串·字符数组
M__3336 分钟前
动态规划进阶:简单多状态模型
c++·算法·动态规划
米优44 分钟前
使用Qt实现消息队列中间件动态库封装
c++·中间件·rabbitmq
N.D.A.K1 小时前
CF2138C-Maple and Tree Beauty
c++·算法
AI视觉网奇1 小时前
ue 5.5 c++ mqtt 订阅/发布 json
网络·c++·json
程序员-King.1 小时前
day159—动态规划—打家劫舍(LeetCode-198)
c++·算法·leetcode·深度优先·回溯·递归
txinyu的博客1 小时前
解析muduo源码之 StringPiece.h
开发语言·网络·c++