16

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

Matthias
  • 4,481
  • 12
  • 45
  • 84
Nasif Imtiaz Ohi
  • 1,563
  • 5
  • 24
  • 45

3 Answers3

20

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.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • can you please tell me how can i go to **additional include directories** in visual studio 2012(version 11.0). i tried to find it but could not. while right clicking on the project, i couldn't find configuration properties. – Nasif Imtiaz Ohi Apr 09 '13 at 12:14
  • 3
    @NasifImtiazOhi right click on the project and go to properties -> configuration properties -> C/C++ -> general.. – Luchian Grigore Apr 09 '13 at 12:14
  • well, i have selected the containing folder there but still gives error! – Nasif Imtiaz Ohi Apr 09 '13 at 12:23
  • 1
    `fatal error C1083: Cannot open include file: 'iGraphics.h': No such file or directory` i am used to work in codeblocks, but for this project i was asked to do it in visual studio with this additional header file. i may have been mistaking something because i am completely new to this IDE – Nasif Imtiaz Ohi Apr 09 '13 at 12:24
  • @NasifImtiazOhi then the path you added isn't the correct one. – Luchian Grigore Apr 09 '13 at 12:25
  • Also make sure you have selected the right platform at the top of the properties window - Win32, x64 or both. It should match the one you are trying to build. – Victor Sand Apr 09 '13 at 12:32
2

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.

PhoenixPerson
  • 272
  • 2
  • 16
1

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.

Victor Sand
  • 2,270
  • 1
  • 14
  • 32
  • yeah.. i did.. and now it's showing in the header file system.. but still while compiling it gives me error- c:\users\pc\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(5): fatal error C1083: Cannot open include file: 'iGraphics.h': No such file or directory i am new to visual studio and at a fix what to do! – Nasif Imtiaz Ohi Apr 09 '13 at 12:10
  • @NasifImtiazOhi You shouldn't do this. The proper solution is the one I posted. Adding existing items is rarely called for, and should only be used if you know what you're doing. – Luchian Grigore Apr 09 '13 at 12:12