C++ Visual Studio 2017 找不到 windows.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43410631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:33:41  来源:igfitidea点击:

Visual Studio 2017 can't find windows.h

c++windows

提问by Marcin Klima

Hell'o I've just installed Visual Studio 2017 (enterprise).I opened my project whom I created in Visual Studio 2015. My project uses windows.h library but VS2017 cannot find this library. How to repair this?

你好,我刚刚安装了 Visual Studio 2017(企业)。我打开了我在 Visual Studio 2015 中创建的项目。我的项目使用 windows.h 库,但 VS2017 找不到这个库。这个怎么修?

回答by ImFonky

My solution was :

我的解决方案是:

  • Open the project properties
  • Into General--> SDK Version
  • I just picked the 10.0.15063.0version instead of 8.1
  • 打开项目属性
  • 进入通用--> SDK 版本
  • 我只是选择了10.0.15063.0版本而不是 8.1

And it worked.

它奏效了。

回答by James Pack

I solved this issue by re-running the Visual Studio Installer and selecting the "Modify" button. Once presented with the Workloads screen I clicked on the "Individual Components" tab and selected all of the latest "Windows 10 SDK" Checkboxes(version 10.0.15063.0). My guess is that the entry for "Desktop C++ x86 and x64" is the one the actually fixes it but it is only speculation because none of those options were checked when I ran the installer and as you can see I checked all of them.

我通过重新运行 Visual Studio 安装程序并选择“修改”按钮解决了这个问题。看到工作负载屏幕后,我单击“单个组件”选项卡并选择所有最新的“Windows 10 SDK”复选框(版本 10.0.15063.0)。我的猜测是“桌面 C++ x86 和 x64”的条目是实际修复它的条目,但这只是推测,因为当我运行安装程序时没有检查这些选项,正如您所看到的,我检查了所有选项。

enter image description here

在此处输入图片说明

回答by Cozzamara

This happens when you have customized include/library paths in legacy projects. If you added your own additional paths in project properties, VisualStudio 2017 can't automatically figure out base paths when switching between platforms/toolsets - normally it automatically puts correct paths there, but if you added customizations, VS won't touch them.

当您在旧项目中自定义包含/库路径时会发生这种情况。如果您在项目属性中添加了自己的其他路径,VisualStudio 2017 在平台/工具集之间切换时无法自动找出基本路径 - 通常它会自动在那里放置正确的路径,但如果您添加了自定义,VS 不会触及它们。

This is legitimate problem which I ran into myself recently when migrating old project targeted for Windows XP into VS2017. None of the answers or comments listed/linked here so far are helpful. I have all legacy SDKs in VisualStudio 2017 installer, and none of that fixed VS not finding essential includes such as <windows.h>. In my case the project was using v120 toolset from VS2013, which is superseded by v140_xp in newer VS.

这是我最近在将针对 Windows XP 的旧项目迁移到 VS2017 时遇到的合理问题。到目前为止,此处列出/链接的所有答案或评论都没有帮助。我在 VisualStudio 2017 安装程序中拥有所有旧版 SDK,并且没有一个固定的 VS 没有找到必要的包括,例如<windows.h>. 就我而言,该项目使用的是 VS2013 中的 v120 工具集,在较新的 VS 中已被 v140_xp 取代。

After setting correct platform and toolset understood by VS2017, I did the following to resolve the problem:

设置正确的VS2017理解的平台和工具集后,我做了以下解决问题:

  • Open project properties, go to VC++ Directories, for 'Include Directories' and for 'Library Directories', choose <Inherit from parent or project defaults>. This will remove your additional paths.

  • Click 'Apply'. This will reset include path to something like $(VC_IncludePath_x86);$(WindowsSdk_71A_IncludePath_x86)(will vary for SDKs).

  • Re-add your extra paths here, or better yet - under C/C++/General -> Additional Include Directories and Linker/General -> Additional Library Directories.

  • 打开项目属性,转到 VC++ 目录,对于“包含目录”和“库目录”,选择<Inherit from parent or project defaults>。这将删除您的其他路径。

  • 单击“应用”。这会将包含路径重置为类似的内容$(VC_IncludePath_x86);$(WindowsSdk_71A_IncludePath_x86)(因 SDK 而异)。

  • 在此处重新添加您的额外路径,或者更好 - 在 C/C++/General -> Additional Include Directories 和 Linker/General -> Additional Library Directories 下。

回答by Zanna

If the installation was ok it should be here:

如果安装没问题,它应该在这里:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um\Windows.h

C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um\Windows.h

So be sure it is on the include path of the project properties.

所以请确保它在项目属性的包含路径上。

Project properties

项目属性

Or if you prefer by manual edit in the .vcxproj file at the IncludePath Tag line:

或者,如果您更喜欢手动编辑 .vcxproj 文件中的 IncludePath 标记行:

<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);C:\Program Files (x86)\Windows Kits\Include.0.15063.0\um;C:\Program Files (x86)\Windows Kits\Include.0.15063.0\shared;</IncludePath>

回答by Thanos

The problem occurs when you migrate your C++ project from a more updated visual studio version to a lesser one. To solve the issue simply go to your : Project's properties-->General-->SDK Version[and here unroll to show installed SDK versions so you downgrade to an available version {Since the required one seems unavailable hence the error}]. Once one of the Available SDKs selected, Apply, and go back to your code, and everything gonna get fixed.

当您将 C++ 项目从更新的 Visual Studio 版本迁移到较小的版本时,就会出现问题。要解决此问题,只需转到您的:项目的属性--> 常规--> SDK 版本[并在此处展开​​以显示已安装的 SDK 版本,以便您降级到可用版本 {由于所需版本似乎不可用,因此出现错误}]。一旦选择了可用的 SDK 之一,应用并返回到您的代码,一切都会得到修复

回答by Aivar

I got it fixed when I simply changed "General => Windows SDK version" to a different version, submitted the changes and then changed it back.

当我简单地将“General => Windows SDK version”更改为不同的版本,提交更改然后将其更改回来时,我就修复了它。

回答by Erik Bongers

TL;DR: make sure the checkbox, marked below, is checked.

TL;DR:确保选中下面标记的复选框。

In the Include Directories Dlgbox, there's an option at the bottom "Inherit from..." that needs to be checked. Somehow it got unchecked after moving a project to a different solution.

在 Include Directories Dlgbox 中,底部有一个选项“Inherit from...”需要勾选。在将项目移动到不同的解决方案后,它以某种方式未被选中。

So, in my case, resetting to defaultsand adding custom paths again wasn't even needed. Screenshot

因此,就我而言,甚至不需要重置为默认值并再次添加自定义路径。 截屏

回答by Pekka Kalevi Yl?nen

My solution was checking paths.

我的解决方案是检查路径。

Include Directories:

包括目录:

C:\Program Files (x86)\Windows Kits\Include.0.17763.0\um;
C:\Program Files (x86)\Windows Kits\Include.0.17763.0\shared;
%(AdditionalIncludeDirectories)

Library Directories:

图书馆目录:

C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.16.27023\lib\x64

and then right click Solution Explorer: Solution 'xxxxx' (1 project) line click "Retarget solution"

然后右键单击解决方案资源管理器:解决方案'xxxxx'(1 个项目)行单击“重定向解决方案”

Remember to set Debug setting for Symbols fetch - Windows 10 must use Microsoft symbol server!

请记住为符号获取设置调试设置 - Windows 10 必须使用 Microsoft 符号服务器!

回答by chokelive

This step work for me. 1. Open visual studio installer 2. at menu "Visual studio comunity 2017" --> click modify 3. at desktop development with c++ --> enable windows10 SDK for desktop and windows 8.1 SDK 4. click modify

这一步对我有用。1. 打开 Visual Studio 安装程序 2. 在菜单“Visual Studio comunity 2017”--> 单击修改 3. 在使用 C++ 进行桌面开发--> 启用 windows10 SDK for desktop 和 windows 8.1 SDK 4. 单击修改

回答by Serg Tsaregorodtsev

I've also installed Visual Studio 2017 (community) first with the default composition settings.I opened my project whom I created in Visual Studio 2015. My project uses windows.h library but VS2017 cannot find this library and other problems. At first I install the missing (SDK 10 ... etc.) components. Part of problems is gone, but windows.h still not found. The problem was solved by completely uninstalling VS2017 and then installing with all the options at once.

我还首先使用默认组合设置安装了 Visual Studio 2017(社区)。我打开了我在 Visual Studio 2015 中创建的项目。我的项目使用 windows.h 库,但 VS2017 找不到这个库和其他问题。起初我安装缺少的(SDK 10 ...等)组件。部分问题消失了,但是windows.h 还是没有找到。通过完全卸载 VS2017 然后立即安装所有选项解决了该问题。