使用CMake和MinGW编译器的Qt Creator

4
我正在尝试在不使用Qt库的情况下,将Qt Creator用于C++ CMake项目。我正在遵循官方指南,但完全不起作用。以下是我的步骤:
  1. 将我的MinGW bin目录添加到PATH
  2. 运行Qt Creator并设置CMake。
  3. 打开一个非常基本的CMakeLists.txt文件。
  4. 选择“Ninja(桌面)”作为CMake生成器。
  5. 从CMake中获取错误。
您可能已经注意到,在官方指南中实际上根本没有提到第4步。我很熟悉CMake,因此我在问自己: 为什么Qt Creator不提供正常的“MinGW Makefiles”生成器?

Ninja or NMake only

最终的问题是:

如何通过CMake使Qt Creator使用MinGW编译器?


已回答的问题:

根据官方指南和通常情况下,当您正确设置PATH时,步骤5不应发生。

为什么CMake找不到在PATH中设置的编译器?

这是Ninja Generator创建这些错误的原因,如果您手动使用CMake进行操作,同样的事情也会发生。

My PATH settings

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!

在查看配置菜单以查看是否忘记设置某些内容时,我偶然发现了编译器设置页面。当然,我也将我的编译器添加到了那里,但它什么也没做。
为什么 CMake 在使用时不使用编译器列表?
如果您在套件选择中选择正确的编译器,则会使用编译器列表。

Options -> Build & Run


你应该添加错误文本以便它们可以被索引。任何引擎都无法索引图像中的文本。这将有助于未来的访问者。例如,Google对“Error required internal CMake variable not set”“CMAKE_CXX_COMPILER_EN_VAR”的搜索结果为0。 - jww
谢谢!我用错误文本替换了图像。此外,我解决了两个问题,还有两个问题未解决。 - Lukas
1个回答

6
通常当你请求帮助,然后不久就自己解决了时,现在我感觉相当愚蠢...
为什么Qt Creator在使用CMake时不使用编译器列表?
它确实使用编译器列表,但只有在将Kit设置为使用正确的编译器时才会使用!
为什么CMake找不到已在PATH中设置的编译器?
这实际上是使用CMake的Ninja生成器的问题。如果直接使用CMake也会出现同样的问题。
为什么Qt Creator不提供普通的“MinGW Makefiles”生成器?
它确实提供,“MinGW Makefiles”生成器只有在您的Kit中选择了MinGW编译器时才会出现。
如何让Qt Creator通过CMake使用MinGW编译器?
通过正确设置一切,并不过分依赖官方指南。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接