Nasif Imtiaz Ohi
Nasif Imtiaz Ohi

Reputation: 1711

visual studio 2012 adding new header file

In Visual Studio 2012 (C++ environment), for a Win32 console application, I need to include a new header file to my project. I tried copying the files in the project's location but that is of no help. The file is iGraphics.h and it is shown in the header files list but does not compile. What should be the correct approach?

enter image description here

Upvotes: 16

Views: 65067

Answers (3)

PhoenixPerson
PhoenixPerson

Reputation: 312

The easiest way to do this is:

  1. Right click on the header file (to be included) in the Solution explorer.
  2. General->"Excluded from the build"
  3. Select "No" from the drop down list
  4. Click "OK".

In VS2012, just using '"' instead of '<>' around the header file in include also works.

Upvotes: 2

Victor Sand
Victor Sand

Reputation: 2340

Put the file in the right place in the file system (like you did). Then right-click your project in the solution explorer and use Add > Existing Item to add it to your project.

If you don't want to move your file (which you probably should not), see Luchian's answer on how to add the include directory to the include folders.

Upvotes: 1

Luchian Grigore
Luchian Grigore

Reputation: 258648

You should add the path to that header to the additional include directories under C/C++ in your project settings. Afterwards, just #include "iGraphics.h" where you need it.

Don't just move header files around, and don't add existing headers to your project for no good reason. This way, you can easily change versions by just specifying a different folder.

Upvotes: 20

Related Questions