Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C1083: Cannot open include file: math.h: No such file or directory

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.

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

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.

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

like image 944
Mr Dog Avatar asked Jun 12 '14 14:06

Mr Dog


3 Answers

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.

If the box is already ticked and Visual Studio isn't finding the directories then try adding these directories yourself:

$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(WindowsSDK_IncludePath)
like image 76
Simple Avatar answered Nov 16 '22 09:11

Simple


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:

#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.

#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:

#include <cmath>
like image 27
Sebastian Mach Avatar answered Nov 16 '22 10:11

Sebastian Mach


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.

like image 2
Gürkan Çetin Avatar answered Nov 16 '22 08:11

Gürkan Çetin