C语言 在 VS2010 命令提示符中编译 C 文件时引用错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7206393/
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-09-02 09:30:06  来源:igfitidea点击:

Reference error while compiling C file in VS2010 command-prompt

cvisual-studio-2010

提问by Pankaj Upadhyay

I have VS 2010 installed on my system and i was trying to compile a simple hello.c in VS command prompt. The compilation gave an error.

我的系统上安装了 VS 2010,我试图在 VS 命令提示符下编译一个简单的 hello.c。编译报错。

Fatal Error C1083: Cannot open include file: 'stdio.h' no such file, folder exist

Fatal Error C1083: Cannot open include file: 'stdio.h' no such file, folder exist

Why this error is coming ?? Does VS2010 not include reference files/assemblies for C.

为什么会出现这个错误??VS2010 是否不包括 C 的参考文件/程序集。

回答by Michael Burr

VS 2010 certainly does contain the standard headers. You should check that your command prompt environment is set up correctly. There should be an environment variable named INCLUDEthat has a directory similar to the cfollowing (among other directories) in it:

VS 2010 确实包含标准头文件。您应该检查您的命令提示符环境是否设置正确。应该有一个名为的环境变量INCLUDE,其中有一个类似于 cfollowing(在其他目录中)的目录:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE

that directory (the name may vary slightly, for example depending on if your machine is a 64-bit OS of not) should include stdio.h

该目录(名称可能略有不同,例如取决于您的机器是否为 64 位操作系统)应包括 stdio.h

If you don't have such a directory in your environment, then you're not setting up the environment correctly. You should use on of the "Visual Studio Command Prompt" shortcuts that VS installs, or simply run

如果您的环境中没有这样的目录,那么您就没有正确设置环境。您应该使用 VS 安装的“Visual Studio 命令提示符”快捷方式,或者直接运行

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat

With the appropriate parameter to get the environment you want (x86or amd64for example).

使用适当的参数来获得您想要的环境(x86amd64例如)。

If the INCLUDEenvironment variable does have an entry like that, but the stdio.hfile doesn't exist, then you might need to reinstall VS.

如果INCLUDE环境变量确实有这样的条目,但该stdio.h文件不存在,那么您可能需要重新安装 VS。

回答by Donald Herman

I had a similar problem as the OP the VC folder was missing most of the files. I tried both repairing and uninstalling/reinstalling VS 2010 but neither worked.

我有一个类似的问题,因为 OP VC 文件夹丢失了大部分文件。我尝试了修复和卸载/重新安装 VS 2010,但都没有奏效。

What worked for me was installing the Microsoft Visual C++ 2010 Redistributable Package (x86).Microsoft Visual C++ 2010 Redistributable Package (x86)

对我有用的是安装 Microsoft Visual C++ 2010 Redistributable Package (x86)。Microsoft Visual C++ 2010 Redistributable Package (x86)

回答by Hyman friup

There are so many versions of so much Windows system code that it's easy for a path to become invalid.

如此多的Windows系统代码的版本如此之多,以至于一条路径很容易变得无效。

In my case:

就我而言:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include

and

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib

needed to be changed to::

需要改为::

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include

and

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib

i.e. v7.1A -> v7.0A(don't ask why, it just part of the everyday, tiresome task of dealing with Microsoft!).

v7.1A -> v7.0A(不要问为什么,这只是与微软打交道的日常工作的一部分!)。

回答by user3613325

I had the same problem. The file stdio.h did not exist in folder include. I removed VS 2010 using the Control Panel then reinstalled, but this didn't solve the problem.

我有同样的问题。文件夹 include 中不存在文件 stdio.h。我使用控制面板删除了 VS 2010,然后重新安装,但这并没有解决问题。

I then used the VS 2010 installation CD to remove all of VS 2010, and manually removed anything leftover by Control Panel. I then installed VS 2010 professional again. The problem was solved.

然后我使用 VS 2010 安装 CD 删除所有 VS 2010,并手动删除控制面板剩余的任何内容。然后我再次安装了VS 2010专业版。问题解决了。