creator找不到编译器 qt_Qt Creator使用MinGW编译器与CMake

本文介绍了在Qt Creator中尝试使用CMake构建非Qt的C++项目时,遇到CMake找不到MinGW编译器的问题。通过分析错误,发现问题出在Ninja生成器上。解决方案是正确设置Qt Creator的工具包,确保选择的编译器与CMake匹配。此外,官方指南可能未明确指出所有必要步骤。
摘要由CSDN通过智能技术生成

I'm trying to use Qt Creator for C++ CMake project which doesn't use the Qt libraries.

I'm following the official guide, but it does not work at all. Here are my steps:

Add my MinGW bin directory to PATH.

Run QtCreator and setup CMake.

Open a a very basic CMakeLists.txt file.

Select "Ninja (Desktop)" as CMake generator.

Getting errors from CMake.

You may have noticed that step 4 is actually not mentioned at all in the official guide. I'm quite used to CMake and as such I'm asking myself:

Why doesn't the Qt Creator offer the normal "MinGW Makefiles" generator?

And finally the ultimate question:

How can I make the Qt Creator use a MinGW compiler through CMake?

Answered questions:

According to the official guide and as usual when you set PATH correctly, step 5 should not happen.

Why doesn't CMake find the compiler set in PATH?

It's the Ninja Generator that creates these errors, the same thing happens if you do it manually with CMake.

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_CXX_COMPILER_ENV_VAR

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_CXX_COMPILER

CMake Error: Could not find cmake module file: D:/Programming/C++/Test/SupportQt/build/CMakeFiles/3.0.2/CMakeCXXCompiler.cmake

CMake Error at CMakeLists.txt:1 (project):

No CMAKE_C_COMPILER could be found.

Tell CMake where to find the compiler by setting the CMake cache entry

CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name

if it is in the PATH.

CMake Error at CMakeLists.txt:1 (project):

No CMAKE_CXX_COMPILER could be found.

Tell CMake where to find the compiler by setting the CMake cache entry

CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler

name if it is in the PATH.

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_C_COMPILER_ENV_VAR

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_C_COMPILER

CMake Error: Could not find cmake module file: D:/Programming/C++/Test/SupportQt/build/CMakeFiles/3.0.2/CMakeCCompiler.cmake

CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.-- Configuring incomplete, errors occurred!

Looking at the configuration menu to see whether I have forgotten to setup something, I stumbled across the compiler setup page. I then of course added my compiler there as well, but it did nothing.

Why doesn't CMake use the compiler list when using CMake?

It does use the compiler list, IF you pick the right compiler in the kits selection.

解决方案

As usually if you ask for help only to shortly after figure it out, I feel quite stupid now...

Why doesn't the Qt Creator use the compiler list when using CMake?

It does, but only if you set the Kit to use the right compiler!

Why doesn't CMake find the compiler set in PATH?

This is actually the problem of the Ninja Generator with CMake. The same thing happens if you use CMake directly.

Why doesn't the Qt Creator offer the normal "MinGW Makefiles" generator?

It does, but only if you picked a MinGW compiler in your Kit!

How can I make the Qt Creator use a MinGW compiler through CMake?

By setting everything up correctly and not relying too heavily on the official guide.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值