1

In a visual C++ project, #include "abc/def/g.h" means: Hey compiler, go to the abc folder which is in the same disk directory as any(first found if there are multiple found; if none is found, then try the directory where the project file is located) of the include paths, then go further down into the def folder and include the g.h file inside it.

Is it true?

The key thing is, path that appears in #include is physical path on the disk, right?

Thanks

h9uest
  • 10,958
  • 3
  • 18
  • 24
  • 1
    Correction: it's not the directory where the *project* file is, but the directory where the including *source* file (.c or .cpp) is. And it's searched first, not last. – Angew is no longer proud of SO Sep 13 '13 at 14:33
  • right - searched first because it's double quoted; If I recall correctly, it will be searched last if it's in <>. Thanks for the quick response! – h9uest Sep 13 '13 at 14:41
  • If you `#include <...>`, the source file's dir will not be searched *at all.* Only the include directories will. – Angew is no longer proud of SO Sep 13 '13 at 14:42
  • @John No, that's a common misunderstanding (that's why I listed the extensions). It's only the *original* source file whose location matters. – Angew is no longer proud of SO Sep 13 '13 at 14:53
  • 1
    @Angew No. The search path for "" included files is implementation defined, for <> is standard mandated, and many common implementations search the directory of the file with the `#include` statement. [Question 179213](http://stackoverflow.com/questions/179213/c-include-semantics) has more details and links to references. – John Sep 13 '13 at 17:51
  • @John Seems it was *my* misunderstanding. And a long-standing one. Thanks for correcting me. The day you stop learning is the day you die... – Angew is no longer proud of SO Sep 13 '13 at 17:58

1 Answers1

1

Yes, your analysis is correct and the path corresponds to physical path on the disk.

But there is a difference when the headers are enclosed in <> and "". When enclosed in <>, the header is present in the standard headers location. But if enclosed in "", it is a user defined header file present in the project's directory.

Mahesh
  • 34,573
  • 20
  • 89
  • 115