我正在尝试在Visual Studio社区2017上构建解决方案,但我不断收到错误“无法打开包含文件:'stdio.h'”。我已经阅读了几个类似的问题,但仍然无法解决这个问题。看起来在stdafx.h文件中调用了stdio.h文件。以下是更多细节。有什么建议? (我无法嵌入图片,所以请点击链接进行截图。)
系统详细信息:Windows 10 Visual Studio Community 2017 v.15.2(26430.6) - 使用C ++安装桌面开发(Screenshot: Installation list)
第1步:我用C ++编写了着名的Hello World程序。
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
第2步:我点击了Build> Build Solution。
问题:'stdio.h':没有这样的文件或目录。完全错误:
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 ==========
故障排除详细信息/我尝试过的事情:
Include Directories $(VC_IncludePath);$(WindowsSDK_IncludePath);
// 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
// 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>
注意:#include
和<stdio.h>
的<tchar.h>
都有下面的红色波浪线,并说“无法打开源文件”。
TRIED:我尝试删除最后两行,但后来我遇到了更多错误。#include "stdafx.h"
。但为了实现这一点,我必须多做一点。请看下面的答案。项目从VS2013移植到VS2017时出现同样的问题, 修复:将“属性 - >常规 - > Windows SDK版本”更改为10
类似的问题对我而言有点不同。我可以编译并运行默认的CUDA 10代码没有问题,但是在编辑窗口中有很多与stdio.h文件相关的错误。这很烦人。我通过将代码文件名从“kernel.cu”更改为“kernel.cpp”来解决它。这是有线的,但对我有用。到目前为止它运行良好。
我在使用Visual Studio 2017 IDE构建VS 2013项目时遇到了同样的问题。解决方案是设置正确的“Platformtoolset v120(Visual Studio 2013)。因此必须安装Windows SDK 8.1。如果要使用Platformtoolset v141(Visual Studio 2017),必须有Windows SDK 10.可以选择Platformtoolset在项目的属性对话框中:常规 - > Platformtoolset
在新计算机上安装VS2017社区并将解决方案从VS2013迁移到VS2017之后,面临丢失stdlib.h
和stdio.h
(以及更多)的问题。
使用过@Maxim Akristiniy的提议,但仍然收到有关工具集兼容性的错误消息。然而,VS本身建议通过在解决方案资源管理器中右键单击解决方案来执行解决方案重新定位,然后从菜单中选择Retarget solution
并从下拉列表中选择更新的Windows SDK Version
。
现在我的项目没有问题。
请注意,您可能需要使项目成为重新定位的启动项目。
有三种方法可以解决这个问题。
#include "stdafx.h"
#include "stdafx.h"
如果您不想将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”(在编译器,构建工具和运行时下):
更新我的VS2017后,我遇到了类似的问题。项目建设很好;但是在编辑器中提出代码时会出现很多“错误”。甚至尝试重新安装VS.我能够通过将“Ignore Standard Include Paths”选项设置为Yes来解决它。尝试构建具有大量错误的解决方案。退回并将选项设置为否。重建后,我的问题消失了。
面对同样的问题,另一种解决方案是添加默认包含,这为我解决了问题:
$(IncludePath);
场景:
解决:
一个脏修复:添加$(VC_IncludePath); $(WindowsSDK_IncludePath);到项目属性/ C / C ++ / General /附加包含目录