简体   繁体   English

无法打开包含文件:'stdio.h' - Visual Studio Community 2017 - C++ 错误

[英]Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error

I am trying to build a solution on Visual Studio Community 2017, but I keep getting the error " Cannot open include file: 'stdio.h' ".我正在尝试在 Visual Studio Community 2017 上构建解决方案,但我不断收到错误“无法打开包含文件:'stdio.h' ”。

I've read through several similar questions, but I still can't fix this problem.我已经阅读了几个类似的问题,但我仍然无法解决这个问题。 It looks like the stdio.h file is called in the stdafx.h file.看起来在stdafx.h文件中调用了stdio.h文件。 Below are more details.以下是更多细节。 Any suggestions?有什么建议么?

System details:系统详情:

  • Windows 10 Windows 10
  • Visual Studio Community 2017 v.15.2 (26430.6) -- Installed Desktop Development with C++ ( Screenshot: Installation list ) Visual Studio Community 2017 v.15.2 (26430.6) -- 使用 C++ 安装桌面开发(截图:安装列表

Step 1: I wrote the famous Hello, World!第 1 步:我写了著名的Hello, World! program in C++. C++ 中的程序。

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello, World!" << endl;
    return 0;
}

Step 2: I clicked on BuildBuild Solution .第 2 步:我点击了BuildBuild Solution

Problem: 'stdio.h' : No such file or directory .问题: 'stdio.h' :没有这样的文件或目录 Full Error:完全错误:

1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>stdafx.cpp
1>c:\users\dahiana mini\desktop\learncpp\helloworld\helloworld\stdafx.h(10):
    fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
1>Done building project "HelloWorld.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Troubleshooting details and things I've tried:故障排除细节和我尝试过的事情:

  1. Configuration Properties * → VC++ Directories Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);配置属性* → VC++ 目录Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);

  2. Screenshot: Solution Explorer (files in the project)屏幕截图:解决方案资源管理器(项目中的文件)

  3. Code in stdafx.cpp file: stdafx.cpp文件中的代码:

     // stdafx.cpp: source file that includes just the standard includes // HelloWorld.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file
  4. Code in stdafx.h file: stdafx.h文件中的代码:

     // stdafx.h: include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently #pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h>

    NOTE: the #include for <stdio.h> and <tchar.h> both have the red squiggle line underneath, and says "cannot open source file".注意: <stdio.h><tchar.h>#include下方都有红色波浪线,并显示“无法打开源文件”。

    Tried: I tried removing the last two lines, but then I got more errors.尝试过:我尝试删除最后两行,但后来出现更多错误。

  5. Tried: Since many suggested that stdafx.h is not required, I tried removing just the first line, #include "stdafx.h" .尝试过:由于许多人建议不需要 stdafx.h,我尝试仅删除第一行#include "stdafx.h" But in order for this to work I had to do a little more.但为了让它发挥作用,我必须做更多的事情。 See the answer below.请参阅下面的答案。

Got same problem with project porting from VS2013 to VS2017,项目从 VS2013 移植到 VS2017 时遇到同样的问题,
Fix: change "Properties->General->Windows SDK Version" to 10修复:将“属性->常规->Windows SDK 版本”更改为 10

Faced the problem of missing stdlib.h and stdio.h (and maybe more) after installing VS2017 Community on a new computer and migrating a solution from VS2013 to VS2017.在新计算机上安装 VS2017 Community 并将解决方案从 VS2013 迁移到 VS2017 后,面临缺少stdlib.hstdio.h (可能还有更多)的问题。

Used @Maxim Akristiniy 's proposal, but still got error message regarding toolset compatibility.使用了@Maxim Akristiniy的提议,但仍然收到有关工具集兼容性的错误消息。 However VS itself suggested to do solution retarget by right-clicking on the solution in Solution Explorer , then selecting Retarget solution from the menu and the updated Windows SDK Version from the drop-down list.然而,VS 本身建议通过右键单击解决方案资源管理器中的解决方案,然后从菜单中选择Retarget solution并从下拉列表中选择更新的Windows SDK Version来执行解决方案重定向。

Now my projects build w/oa problem.现在我的项目构建没有问题。

Note that you may need to make the project your startup project for the retargeting to catch.请注意,您可能需要将该项目设为您的启动项目,以便进行重新定位。

There are three ways to solve this issue.有三种方法可以解决这个问题。

  1. Ignore Precompiled Headers #1忽略预编译头 #1
    Steps: Project > Properties > Configuration Properties > C/C++ > Command Line > in the Additional Options box add /Y-.步骤:项目 > 属性 > 配置属性 > C/C++ > 命令行 > 在附加选项框中添加 /Y-。 ( Screenshot of Property Pages ) > Ok > Remove #include "stdafx.h" 属性页的屏幕截图)> 确定 > 删除#include "stdafx.h"
  2. Ignore Precompiled Headers #2忽略预编译头 #2
    Steps: File > New > Project > ... > In the Application Wizard Window click Next > Uncheck the Precompiled Header box > Finish > Remove #include "stdafx.h"步骤:文件 > 新建 > 项目 > ... > 在应用程序向导窗口中单击下一步 > 取消选中预编译头框 > 完成 > 删除#include "stdafx.h"
  3. Reinstall Visual Studio重新安装 Visual Studio
    This also worked for me, because I realized that maybe there was something wrong with my Windows SDK.这也对我有用,因为我意识到我的 Windows SDK 可能有问题。 I was using Windows 10, but with Windows SDK 8.1.我使用的是 Windows 10,但使用的是 Windows SDK 8.1。 You may have this problem as well.你可能也有这个问题。
    Steps: Open Visual Studio Installer > Click on the three-lined Menu Bar > Uninstall > Restart your computer > Open Visual Studio Installer > Install what you want, but make sure you install only the latest Windows SDK 10, not multiple ones nor the 8.1.步骤:打开 Visual Studio 安装程序 > 单击三行菜单栏 > 卸载 > 重新启动您的计算机 > 打开 Visual Studio 安装程序 > 安装您想要的,但请确保您只安装最新的 Windows SDK 10,而不是多个或 8.1 .

    The first time I installed Visual Studio, I would get an error stating that I needed to install Windows SDK 8.1.我第一次安装 Visual Studio 时,会收到一条错误消息,指出我需要安装 Windows SDK 8.1。 So I did, through Visual Studio Installer's Modify option.所以我做了,通过 Visual Studio 安装程序的修改选项。 Perhaps this was a problem because I was installed it after Visual Studio was already installed, or because I needed SDK 10 instead.也许这是一个问题,因为我是在安装 Visual Studio 之后安装的,或者因为我需要 SDK 10。 Just to be safe I did a complete reinstall.为了安全起见,我进行了完整的重新安装。

For CUDA:对于 CUDA:

Right Click on your project.右键单击您的项目。

Go to Properties->CUDA and set " CUDA Toolkit Custom Dir " to your CUDA toolkit directory.转到Properties->CUDA并将“ CUDA Toolkit Custom Dir ”设置为您的 CUDA 工具包目录。

For me it was: C:\\\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0对我来说是: C:\\\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.0

在此处输入图片说明

以防万一您不想将 Windows SDK 撞到 Windows 10(例如,您可能正在从事一个不由您做出决定的开源项目),您可以通过以下方式在 Windows SDK 8.1 项目中解决此问题导航Tools -> Get Tools and Features... -> Individual Compontents tab并安装单个组件“Windows 8.1 SDK”(在 SDK、库和框架下)和“Windows Universal CRT SDK”(在编译器、构建工具和运行时下) :

If you run into this problem with Visual Studio 2019 (VS2019) , you can download the build tools from https://visualstudio.microsoft.com/downloads/ .如果您在使用Visual Studio 2019 (VS2019) 时遇到此问题,您可以从https://visualstudio.microsoft.com/downloads/下载构建工具。 And, under Tools for Visual Studio 2019 and download Build Tools for Visual Studios 2019 .并且,在 Tools for Visual Studio 2019 下并下载Build Tools for Visual Studios 2019

面对同样的问题,另一种解决方案是添加默认包含,这为我解决了问题:

$(IncludePath);

Scenario:设想:

  1. Windows 10 with Visual Studio 2017 (FRESH installation).带有Visual Studio 2017 的Windows 10 (全新安装)。

  2. 'C' project ( ERROR like -> cannot open source file : 'stdio.h', 'windows.h', etc.). “C”项目错误如 ->无法打开源文件:“stdio.h”、“windows.h”等)。

Resolve:解决:

  1. Run ' Visual Studio Installer '.运行“ Visual Studio 安装程序”。

  2. Click button 'Modify'.单击“修改”按钮。

  3. Select ' Desktop development with C++ '.选择“使用 C++ 进行桌面开发”。

  4. From "Installation details"(usually on the right-sidebar) select:从“安装详细信息”(通常在右侧栏)中选择:

    4.1. 4.1. Windows 10 SDK(10.0.17134.0) . Windows 10 SDK(10.0.17134.0)

    • Version of SDK in 4.1. 4.1 中的 SDK 版本。 is just for example.只是举例。
  5. Click button 'Modify', to apply changes.单击“修改”按钮以应用更改。

  6. Right-click 'SomeProject' -> 'Properties'.右键单击“SomeProject”->“属性”。
  7. 'Configuration:' -> 'All Configurations' and 'Platform:' -> 'All Platforms'. “配置:”->“所有配置”和“平台:”->“所有平台”。
  8. 'Configuration Properties' -> 'General' -> ' Windows SDK Version ': “配置属性”->“常规”->“ Windows SDK 版本”:
    • change(select from combobox) SDK version to currently installed ;将(从组合框中选择)SDK 版本更改为当前安装的版本;
  9. Click button 'Apply', to apply changes.单击“应用”按钮以应用更改。

A dirty fix: Add $(VC_IncludePath);$(WindowsSDK_IncludePath);一个肮脏的修复:添加 $(VC_IncludePath);$(WindowsSDK_IncludePath); into project Properties / C/C++ / General / Additional include directories进入项目 Properties / C/C++ / General / Additional include 目录

I had a similar problem after updating my VS2017.更新我的 VS2017 后我遇到了类似的问题。 Project built fine;项目建设良好; but lots of 'errors' when code was brought up in the editor.但是在编辑器中调出代码时会出现很多“错误”。 Even tried reinstalling VS.甚至尝试重新安装VS。 I was able to solve it by setting the option “Ignore Standard Include Paths” to Yes.我能够通过将选项“忽略标准包含路径”设置为是来解决它。 Attempted to build the solution with lots of errors.试图构建有很多错误的解决方案。 Went back and set the option to No. After rebuilding, my problem went away.返回并将选项设置为否。重建后,我的问题消失了。

Similar problem for me but a little different.对我来说类似的问题,但有点不同。 I can compile and run the default CUDA 10 code with no problem, but there are a lots of error related to the stdio.h file show in the edit window.我可以毫无问题地编译和运行默认的 CUDA 10 代码,但是有很多与编辑窗口中显示的 stdio.h 文件相关的错误。 Which is annoying.这很烦人。 I solve it by change the code file name from "kernel.cu" to "kernel.cpp".我通过将代码文件名从“kernel.cu”更改为“kernel.cpp”来解决它。 That is wired but works for me.那是有线的,但对我有用。 And it runs well so far.到目前为止,它运行良好。

Same issue I was getting.我遇到了同样的问题。 Run 'Visual Studio Installer'->Modify->Windows 10 SDK(10.0.17134.0).运行“Visual Studio 安装程序”->修改->Windows 10 SDK(10.0.17134.0)。 wait for update to finish.等待更新完成。 Restart your computer.重新启动计算机。

open VS-2017 and open your project.打开 VS-2017 并打开您的项目。

Right click on project solution explorer.右键单击项目解决方案资源管理器。 Select "Retarget Solution" and then select "Windows 10 SDK(10.0.17134.0)".选择“重定向解决方案”,然后选择“Windows 10 SDK(10.0.17134.0)”。 It worked for me.它对我有用。

For me the problem was a lack of rights on my Windows account.对我来说,问题是我的 Windows 帐户没有权限。 The following url's helped me to identify the problem:以下网址帮助我确定了问题:

stdio.h in Visual Studio Visual Studio 中的 stdio.h

Microsoft C++ Compiler, Fatal Error C1083: Cannot open include file 'stdio.h' Microsoft C++ 编译器,致命错误 C1083:无法打开包含文件“stdio.h”

https://social.msdn.microsoft.com/Forums/vstudio/en-US/5402a5ae-82e5-4370-9297-5be12152ce5e/standard-users-cannot-open-windowsh-using-x64-native-tools https://social.msdn.microsoft.com/Forums/vstudio/en-US/5402a5ae-82e5-4370-9297-5be12152ce5e/standard-users-cannot-open-windowsh-using-x64-native-tools

Most notably the text "your standard users must have access to registry editing tools if they want to compile win32 projects using Native Tools".最值得注意的是文本“如果您的标准用户想要使用本机工具编译 win32 项目,他们必须有权访问注册表编辑工具”。 I switched user in Windows an logged in with an admin account and the problem was gone.我在 Windows 中切换用户并使用管理员帐户登录,问题就消失了。

I had the same problem building VS 2013 Project with Visual Studio 2017 IDE.我在使用 Visual Studio 2017 IDE 构建 VS 2013 项目时遇到了同样的问题。 The solution was to set the right "Platformtoolset v120 (Visual Studio 2013). Therefor there must be the Windows SDK 8.1 installed. If you want to use Platformtoolset v141 (Visual Studio 2017) there must be Windows SDK 10. The Platformtoolset can be chosen inside the properties dialog of the project: General -> Platformtoolset解决方案是设置正确的“Platformtoolset v120 (Visual Studio 2013)。因此必须安装Windows SDK 8.1。如果要使用Platformtoolset v141 (Visual Studio 2017),则必须安装Windows SDK 10。可以选择Platformtoolset在项目的属性对话框中:General -> Platformtoolset

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

相关问题 Visual Studio 2017 for Dymola 无法打开 stdio.h - Visual Studio 2017 for Dymola cannot open stdio.h 在新的 Visual Studio 2017 社区项目中找不到 stdio.h - can't find stdio.h in new Visual Studio 2017 Community project VS Code '无法打开源文件 "stdio.h" C/C++' - VS Code 'cannot open source file "stdio.h" C/C++' Microsoft Visual Studio Community 2019:致命错误 C1083:无法打开包含文件:'corecrt.h':没有这样的文件或目录 - Microsoft Visual Studio Community 2019: fatal error C1083: Cannot open include file: 'corecrt.h': No such file or directory Visual Studio Build Tools 14 找不到 stdio.h - Visual Studio Build Tools 14 cannot find stdio.h Visual Studio 2017 C ++项目中的Boost C ++库-“无法打开包含文件” - Boost C++ Libaries in Visual Studio 2017 C++ Project - “Cannot open include file” Visual Studio 2010 C ++,无法打开包含文件:'afxwin.h','TCHAR.H'和'cassert' - Visual Studio 2010 C++, Cannot open include file: 'afxwin.h', 'TCHAR.H', and 'cassert' 使用stdio.h重定位和重命名文件C ++ - Relocating and renaming file C++ using stdio.h stdio.h 在 C++ 中不是标准的? - stdio.h not standard in C++? 为什么MS Visual Studio #include <stdio.h> 默认情况下在stdafx.h中? - Why does MS Visual Studio #include <stdio.h> in stdafx.h by default?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM