Reputation: 25353
Sorry for posting such a lowly beginner's question, but I just still don't know my way around Visual Studios yet. I'm trying to compile a code in C++ Visual Studios:
#include "Banana.h"
int main(int argc, char* argv[])
{
fruit::Banana banana;
banana.dance();
return 0;
}
and I'm getting an error
fatal error C1083: Cannot open include file: 'Banana.h': No such file or directory
But in the Solution Explorer under the project that I'm working with there is a source folder labeled "fruit/Header Files" and within that folder is "Banana.h". I thought that everything in the source folders within the same project were automatically on the source path. What gives?
Upvotes: 14
Views: 18205
Reputation: 146910
It's very confusing, because the Solution Manager uses virtual filepaths, whereas #include uses real filepaths. This way, you can make filters in SM and have no disk change, and add files that you can't include, etc.
Upvotes: 0
Reputation: 57036
The Solution Explorer doesn't show if the .h files are actually usable. Whether a header file is usable depends on whether it's reachable, which is determined by the list of directories to include from. I think the solution includes header files so it knows to recompile if they change.
Upvotes: 4
Reputation: 308091
You will need to configure additional include paths. If you go to the Project Properties, you'll find it under Configuration Properties
, C/C++
at the top.
Upvotes: 17
Reputation: 46607
Right-click on the tab header of the source code file and choose open file location
. Then, start there and try to locate the Banana.h
file and move it either to the same directory (and re-add it to the solution), or change the #include
line accordingly. You could also add the directory where Banana.h
is located to the list of include paths (project settings -> c++ -> include directories
).
Upvotes: 2