C++ Visual Studios : can not open include file ... eh?
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 t开发者_开发知识库here 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?
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.
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.
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
).
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.
精彩评论