Qt Creator使用MinGW编译器和CMake

Luk*_*kas 4 windows mingw cmake qt-creator

我正在尝试将Qt Creator用于不使用Qt库的C++ CMake项目.

我正在遵循官方指南,但它根本不起作用.这是我的步骤:

  1. 将我的MinGW bin目录添加到PATH.
  2. 运行QtCreator并设置CMake.
  3. 打开一个非常基本的CMakeLists.txt文件.
  4. 选择"Ninja(桌面)"作为CMake生成器.
  5. 从CMake获取错误.

你可能已经注意到官方指南中根本没有提到第4步.我已经习惯了CMake,因此我问自己:

为什么Qt Creator不能提供正常的"MinGW Makefiles"生成器?

忍者或仅限NMake

最后是最终的问题:

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


回答的问题:

根据官方指南,正常情况下,如果设置PATH正确,步骤5不应该发生.

为什么CMake没有找到编译器集PATH?

这是Ninja Generator产生这些错误,如果你用CMake手动完成同样的事情.

我的PATH设置

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!
Run Code Online (Sandbox Code Playgroud)

查看配置菜单以查看我是否忘记设置某些内容,我偶然发现了编译器设置页面.我当然也在那里添加了我的编译器,但它没有做任何事情.

为什么CMake在使用CMake时不使用编译器列表?

它确实使用了编译器列表,如果您在套件选择中选择了正确的编译器.

选项 - >构建和运行

Luk*_*kas 5

通常情况下,如果你在弄清楚之后不久就寻求帮助,我现在觉得很愚蠢......

使用CMake时,为什么Qt Creator不使用编译器列表?

它确实如此,但只有在您将Kit设置为使用正确的编译器时!

Qt Creator套件

为什么CMake没有在PATH中找到编译器集?

这实际上是带有CMake的Ninja Generator的问题.如果你直接使用CMake,会发生同样的事情.

为什么Qt Creator不能提供正常的"MinGW Makefiles"生成器?

它确实如此,但前提是您在套件中选择了MinGW编译器!

MinGW发电机

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

通过正确设置一切,而不是过分依赖官方指南.

有用!