C++ C1083:无法打开包含文件:math.h:没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24186647/
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
C1083: Cannot open include file: math.h: No such file or directory
提问by Mr Dog
I have a bunch of these errors and am at a dead end.
我有一堆这样的错误,而且已经走到了尽头。
Found plenty of answers on google but unfortunately none of them work
在谷歌上找到了很多答案,但不幸的是它们都不起作用
I am using Visual Studio 2012.
我正在使用 Visual Studio 2012。
All the files it says is cant find are on my computer in this folder
它说找不到的所有文件都在我电脑上的这个文件夹中
C:\Program Files\Microsoft Visual Studio 11.0\VC\include
Even when I right click on the include statement and click on 'Open Document ' it takes me to the document, so it is clearly there and can be seen
即使我右键单击 include 语句并单击“打开文档”,它也会将我带到该文档,因此它很明显在那里并且可以看到
I tried adding the directory to the 'Additional Directories' field in options too but did not solve it.
我也尝试将目录添加到选项中的“附加目录”字段,但没有解决。
If I use the include statement with the full path like so :
如果我使用包含完整路径的语句,如下所示:
#include <C:\Program Files\Microsoft Visual Studio 11.0\VC\include\math.h>
Then is works but if the math.h file has any include statements I need to add the path to them as well and so on.
然后是有效的,但如果 math.h 文件有任何包含语句,我还需要向它们添加路径等等。
Any Idea what is happening and what else I can try?
知道发生了什么,我还能尝试什么?
EDIT: Going to try and create a new project from scratch and see if that helps. It is possible I touched a settings I shouldn't have
编辑:尝试从头开始创建一个新项目,看看是否有帮助。有可能我触及了我不应该拥有的设置
采纳答案by Simple
Right-click your project, go to Properties, then go to VC++ Directories and open the editor for Include Directories. There should be a tick box labelled "Inherit from parent or project defaults". You will see that Visual Studio includes some predefined directories.
右键单击您的项目,转到属性,然后转到 VC++ 目录并打开包含目录的编辑器。应该有一个标记为“从父级或项目默认值继承”的复选框。您将看到 Visual Studio 包含一些预定义的目录。
If the box is already ticked and Visual Studio isn't finding the directories then try adding these directories yourself:
如果该框已被勾选并且 Visual Studio 未找到目录,则尝试自己添加这些目录:
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(WindowsSDK_IncludePath)
回答by Sebastian Mach
The following is not correct in multiple ways:
以下在多个方面都不正确:
#include <C:\Program Files\Microsoft Visual Studio 11.0\VC\include\math.h>
\...
begins a so called escape sequence, therefore you are putting the special tokens \P
, \M
, \V
, \i
and \m
into the string, but unlike for example \n
, which denotes a the newline character, these do not exist as valid escape sequences. This can be fixed by using forward slash consistently:
\...
开始一个所谓的转义序列,因此您将特殊标记\P
, \M
, \V
,\i
和\m
放入字符串中,但与例如\n
表示换行符的 不同,它们不作为有效的转义序列存在。这可以通过始终使用正斜杠来解决:
#include <C:/Program Files/Microsoft Visual Studio 11.0/VC/include/math.h>
However, math.h
is a standard header. For standard headers, you don't write the full path. For non-standard headers, you add the include-path to the project setup, and don't write the full path neither.
然而,math.h
是一个标准的标题。对于标准标题,您无需编写完整路径。对于非标准标头,您将包含路径添加到项目设置中,并且也不要写入完整路径。
#include <math.h>
Then: You are in C++, not in C. The C++ equivalents of the C-headers usually have the .h
extension removed, and a c
appended to the front:
然后:您使用的是 C++,而不是 C。C 头文件的 C++ 等效项通常会.h
删除扩展名,并c
在前面附加一个:
#include <cmath>
回答by Gürkan ?etin
I've just had the same problem, and my solution was simply to place the filename in quotes instead of angle brackets.
我刚刚遇到了同样的问题,我的解决方案只是将文件名放在引号中而不是尖括号中。
So, instead of < dog.h> , "dog.h" solved the "file not found" problem.
因此,代替 < dog.h> ,“dog.h”解决了“找不到文件”的问题。
回答by AriesConnolly
This is a bug in Visual Studio that Micosoft has set to "Closed - not a bug" see the link
这是 Visual Studio 中的一个错误,Micosoft 已将其设置为“已关闭 - 不是错误”,请参阅链接
https://developercommunity.visualstudio.com/content/problem/311530/win10-sdk-broken.html
https://developercommunity.visualstudio.com/content/problem/311530/win10-sdk-broken.html
I searched my PC for math.h and found it in a sub folder under "Program Files\Unity", i.e. Visual Studio did not install it. I seem to have the reverse midas touch this weekend, everything I touch turns to crap.
我在我的 PC 上搜索 math.h 并在“Program Files\Unity”下的子文件夹中找到它,即 Visual Studio 没有安装它。这个周末我似乎有相反的点石成金,我接触的一切都变成了废话。