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)
相关推荐
tjl521314_211 天前
04C++ 名称空间(Namespace)
开发语言·c++
ximu_polaris1 天前
设计模式(C++)-行为型模式-备忘录模式
c++·设计模式·备忘录模式
wdfk_prog1 天前
正常关闭虚拟机时,不要点“关机”,而要点“关闭客户机”
linux·c语言·网络·ide·vscode
tankeven1 天前
C++ 智能指针
c++
handler011 天前
【算法模板】最小生成树:稠密图选 Prim,稀疏图选 Kruskal
c语言·数据结构·c++·算法
许长安1 天前
RPC 异步调用基本使用方法:基于官方helloworld-async 示例
c++·经验分享·笔记·rpc
sparEE1 天前
c++面向对象:对象的赋值
开发语言·c++
此生决int1 天前
快速复习之数据结构篇——栈和队列
数据结构·c++
H_BB1 天前
第17届蓝桥杯备战历程
c++·算法·职场和发展·蓝桥杯
daad7771 天前
记录一次上下文切换次数的统计
服务器·c++·算法