项目启动时未定义 QT COMPILER_MACROS [英] QT COMPILER_MACROS not defined on project start

查看:797
本文介绍了项目启动时未定义 QT COMPILER_MACROS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 QT(版本 5.12.1)时遇到了一个烦人的问题,我怀疑这是因为我的机器上还有几个不同版本的 Visual Studio 也处于活动状态.请注意,我使用的是 Windows 10 并使用 QT Creator.问题如下:

I have an annoying issue with QT (version 5.12.1) and I suspect it's because I have a few different versions of Visual Studio also active on my machine. Note that I'm using windows 10 and working with QT creator. The issue is as follows:

当我创建一个新的空控制台项目时,我在 IDE 中收到以下一般消息:

When I create a new empty console project, I get the following general message in the IDE:

运行 Windows 运行时设备检测.未找到 winrtrunner.exe.C:/Qt/Qt5.12.1/5.12.1/mingw73_64/mkspecs/features/toolchain.prf(76):变量 QMAKE_CXX.COMPILER_MACROS 未定义.项目错误:无法从编译器输出错误解析默认搜索路径,而解析文件 C:\Qt\Test\Proj\Proj.pro.放弃.

Running Windows Runtime device detection. No winrtrunner.exe found. C:/Qt/Qt5.12.1/5.12.1/mingw73_64/mkspecs/features/toolchain.prf(76): Variable QMAKE_CXX.COMPILER_MACROS is not defined. Project ERROR: failed to parse default search paths from compiler output Error while parsing file C:\Qt\Test\Proj\Proj.pro. Giving up.

在制作控制台项目时,QT会默认添加main.cpp.但是,我无法添加任何新的源代码文件(这些选项呈灰色显示)并且我实际上无法访问 main.cpp.

When making a console project, QT will by default, add main.cpp. However I can't add any new source code files (those options are greyed out) and I can't actually access main.cpp.

但是,如果我构建项目(通过 IDE),它将生成 .o 和 .exe 文件,这些文件毫无意义,因为我无法向源代码添加任何内容.然后,我关闭 QT,打开它,一切正常.

But if I build the project (via the IDE) it will make a the .o and .exe files, which are meaningless because I've not been able to add anything to the source code. Then, I close QT, open it, and it all works as it should.

我使用的是 MinGW,但是 QT 仍然可以自动检测 MSVC 编译器和调试器.这应该不会导致任何问题,因为默认构建工具包指定了所有 MinGW 的东西.

I'm using MinGW, however QT can still autodetect the MSVC compilers and debuggers. That shouldn't cause any problems because the default build kit specifies all the MinGW stuff.

任何想法可能是什么原因?我所做的所有在线搜索都指向记录和修复 QT5.9 的错误,但没有明确解决我的问题.

Any ideas what the reason could be? All the online searching I've done points towards bugs being logged and fixed for QT5.9, but no clear solution for my problem.

推荐答案

我们在 Windows 10 上构建时遇到了同样的问题,我想我找到了解决方案.我们的项目正在使用 Visual Studio 2019(使用 MSVC 编译器)和 Qt 5.12.7(使用 MinGW 64 位编译器)编译我们的 Qt 项目.

We were having the same problem building on Windows 10, and I think I found a solution. Our project is compiling our Qt project with both Visual Studio 2019 (using the MSVC compiler), and with Qt 5.12.7 (using a MinGW 64bit compiler).

我们有一个相当大的重构,所以我删除了构建目录和 *pro.user 文件.然后我在我们的 Qt 项目中发生了同样的事情.我还创建了一个默认项目,关闭了 Qt,当我重新启动它时,我无法解析 *.pro 文件,并出现与您看到的相同的错误.经过一番调查,我恢复了我(从回收站)删除的 .qmake.stash 文件,并且构建再次开始工作.

We had a pretty big refactor, so I deleted build directories and *pro.user files. Then I had the same thing happen to our Qt projects. I also created a default project, closed Qt and when I restarted it, I could not parse the *.pro file with the same error you saw. After some investigation, I restored .qmake.stash files that I had deleted (from the Recycle Bin) and the build started working again.

我发现 Qt 依赖于 qmake 的运行(这个错误应该被修复:https://bugreports.qt.io/browse/QTBUG-60059,但我决定专注于 qmake).经过一系列反复试验(没有很好地解释其工作原理),我找到了解决方案.

What I pieced out is that Qt depends on qmake running (This bug was supposed to be fixed: https://bugreports.qt.io/browse/QTBUG-60059, but I decided to focus on qmake). After a bunch of trial and error (without a good explanation of why it work), I found a solution.

我让这个程序运行了几次.

I got this procedure to work a few times.

  • 删除任何构建工件和 *pro.user 文件
  • 打开项目并将其配置为 MinGW 64 位.
  • 获取错误
  • 构建->运行qmake(您可以查看编译输出以查看它是否正常运行)
  • 点击文件"->关闭项目
  • 点击文件"->最近的项目,然后选择您的项目再次打开.
  • 现在解决了!
  • 注意安全并进行构建.

此外,只要您在 QtCreator 关闭时不吹走所有构建工件,打开项目似乎就可以找到.您可以在 QtCreator 打开时清除所有工件,然后在关闭之前重建,一切正常.

Also, as long as you don't blow away all the build artifacts while QtCreator is closed, opening the project seems to work find. You can blow away all the artifacts while QtCreator is open, and then rebuild before closing and everthing works ok.

这篇关于项目启动时未定义 QT COMPILER_MACROS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆