VC++ Visual Studio added .hpp files in subdirectory but get "Error: cannot open source file ..."

10,259

Solution 1

Workaround;

Add the files to a directory outside of the project and then reference those directories in the "Additional Include Directories" in Properties -> Configuration Properties -> C/C++ -> General.

Why I can't add additional directories within the project and have Visual Studio rescan them (like an Eclipse refresh) is beyond me.

Solution 2

Please see the answer at the following question. This answer fixed the problem for me. It has to do with adding $(ProjectDir) in the "C/C++ Include Directory" in the project settings.

"Cannot open include file" error in VS2010

The answer linked above, fixed my issue with not being able to include subdirectory files inside of the project. I hope this helps anyone else having this issue.

Thanks,

Share:
10,259
earcam
Author by

earcam

OSGi love-struck

Updated on June 28, 2022

Comments

  • earcam
    earcam almost 2 years

    This is driving me nuts - I've added a number of .hpp files in subdirectories in the root of an existing VC++ projects source directory.

    Visual Studio complains "Error: cannot open source file ..." but if I right click on the and select open document, VS can display it.

    I've tried:

    • "Rescan solution" which appears to do nothing.
    • Adding existing item (both on it's own and with a "filter" - which appears to be a directory?)
    • Closing the project and VStudio in the vain hope it would eventually discover the directories/files I'd added

    VStudio complains it cannot find these files when it is capable of opening them? My question is simply this: "How can I add a directory containing source files to a VC++ project such that the linker/complier can see them?

    (disclaimer; i've never used Visual Studio before or many Microsoft products, so am finding this all very alien)