简体   繁体   English

Qt 自动生成的.rc 文件无法打开包含文件'windows.h'

[英]Qt automatically generated .rc file cannot open include file 'windows.h'

In my Qt 5.9.1 project, I wanted to add version info to the executable to help with debugging.在我的 Qt 5.9.1 项目中,我想将版本信息添加到可执行文件以帮助调试。 So, I added VERSION = 1.0.0 to the 'Project.pro' file, which automatically generated a 'Project_resource.rc' file, as expected from Qt Version .因此,我将VERSION = 1.0.0添加到“Project.pro”文件中,该文件自动生成了一个“Project_resource.rc”文件,正如Qt 版本所预期的那样。

However, the project now fails to compile, giving the error RC1015: cannot open include file 'windows.h' on the line #include <windows.h> in 'Project_resource.rc'.但是,该项目现在无法编译,出现错误RC1015: cannot open include file 'windows.h' on line #include <windows.h> in 'Project_resource.rc'。 I know that windows.h is known by the compiler at another point in the program, because in main.cpp I #include <windows.h> and use a function from there, and that successfully compiles.我知道windows.h在程序的另一点被编译器知道,因为在main.cpp#include <windows.h>并使用 function 从那里成功编译。 I just can't figure out why the 'Project_resource.rc' can't find that same file.我只是想不通为什么“Project_resource.rc”找不到同一个文件。

Note: I have the following above the VERSION = 1.0.0 line in 'Project.pro', which is how my main.cpp can find <windows.h> .注意:我在“Project.pro”中的VERSION = 1.0.0行上方有以下内容,这就是我的main.cpp可以找到<windows.h>的方式。

INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64"
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/um"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/um/x64"
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/shared"

Remember.rc files have their own AdditionalIncludeDirectories.记住.rc 文件有自己的 AdditionalIncludeDirectories。

It's possible that your project had set the Windows SDK properly set as one of the Include Directories values (hence your.cpp file resolves the windows.h header file) but not the.rc file (which would explain why windows.h can't be resolved from it). It's possible that your project had set the Windows SDK properly set as one of the Include Directories values (hence your.cpp file resolves the windows.h header file) but not the.rc file (which would explain why windows.h can't从中得到解决)。

If you're using Visual Studio 2019, try this:如果您使用的是 Visual Studio 2019,请尝试以下操作:

  1. Right click your.rc file on the Solution Explorer右键单击解决方案资源管理器上的 your.rc 文件
  2. Go to Resources -> General Go 到资源 -> 常规
  3. Edit the Additional Include Directories编辑其他包含目录
  4. Include $(WindowsSDK_IncludePath) Macro包含 $(WindowsSDK_IncludePath) 宏
  5. Be sure to accept and save the change.请务必接受并保存更改。

You should stop seeing this error right after having done this.完成此操作后,您应该立即停止看到此错误。 If the ".rc file cannot open include file" was referring to a different file, just try the same but use the proper macro/path value on step 4.如果“.rc 文件无法打开包含文件”指的是不同的文件,只需尝试相同的方法,但在步骤 4 中使用正确的宏/路径值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM