Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio cannot include header file.

Tags:

Visual studio projects have a folder for header files. So, I put the header file in there thinking I would be able to type #include "SDL.h", but that didn't work. I did some searching for it and found nothing helpful.

error

like image 666
Itchy Nekotorych Avatar asked Sep 24 '12 08:09

Itchy Nekotorych


People also ask

How do I include a .h file in Visual Studio?

Place your caret on the first line of any C# or Visual Basic file. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Add file header. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option.

Why are there no header files in C#?

The main reason is that you can distribute your header files to third parties or customers with your DLL, so they can access to all the types and the compiler can warn you if there is any problem. C# actually removes the concept of header files BUT you can still do it in the same way as C++.

Can you include header files in header files?

Yes, this will work. Note, however, that if you include a lot of headers in this file and don't need all of them in each of your source files, it will likely increase your compilation time.


2 Answers

Putting the header there only helps organize your files, it doesn't copy the file to the include directories nor makes it automatically visible.

You'll need to add the path to where SDL.h is located to your project additional include directories.

Just right-click on the project -> Configuration Properties -> C/C++ -> General -> Additional Include Directories.

In fact, you shouldn't have to add SDL.h to the solution, having the path in the Additional Include Directories is enough.

like image 59
Luchian Grigore Avatar answered Sep 21 '22 03:09

Luchian Grigore


This folder view that you can see on the left is just project organisation hierarchy - it does not reflect your disk hierarchy and the actual location on the disk of your file can be totally different. And #include takes into account your disk location (and all the search paths set in the project properties)

So, to make short: - Check if your SDL.h file is in a reachable location on disk :)

like image 27
Fszczemton Avatar answered Sep 20 '22 03:09

Fszczemton