Difference between #include "filename.h", #include <filename.h>, and *.h-files located in a subfolder /src/filename.h

Hi everybody,

I'm asking this because I don't know it exactly.
most header-files are included with sharp-edged bracktes < >


#include <MyHeaderFile.h>

rather few are with double-hyphen

#include "SomeOtherFile.h"

So what is the difference?

And as a second question:
Some libraries have a subfolder "src" and then the *.h / *.cpp-files are located in this subfolder "src"

How does the compiler deal with additional *.h-files that have a different name then the library-folder itself?


Most of the time writing the include-lines in this way works

#include <RobotIRremote.h>
#include <RobotIRremoteTools.h>

But sometimes the compiler is unable to find additional files
and then the compiler complaints "no such file or directory"

best regards Stefan

for files included with < > the C++ preprocessor doesn't search for the include file in the same folder as the file which includes it.

What can be very confusing is that, even when the angle brackets #include syntax would be most appropriate, the quotes syntax will almost always work. So you will find that even very smart and experienced (yet sloppy) people often use the two syntaxes completely randomly, meaning that it is impossible to interpolate correct usage from the existing code.

This is known as the "recursive layout". Technical details about that here in the Arduino Library Specification:

There is no requirement for even the primary header files to match the library folder.

In cases where there are two libraries which both contain a header file matching an #include directive, the closeness of match between the library folder name and the header file name is one of the factors used to decide which of the two libraries should be used. More details about that and descriptions of all the factors are here:
That is the only way the match between header and folder name matters. This is also completely unrelated to the presence or absence of a src subfolder because the library folder name that is used is that of the library's root folder, not the src subfolder.

Please provide a specific example of this, including all the details we would need to reproduce the error.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.