Managing Include Files

My sketch includes a file (Robot.h) that contains many defines that control what code is actually generated.

Both the sketch and Robot.h are in the same folder. They reference many libraries that I have built. I created these libraries in the same folder as the sketch, but then moved them to folders in the Libraries folder so they could be reused by other programs.

Now the compile cannot find the Robots.h file. I need to better understand how the compiler locates files that it includes. I was under the impression that it will look for "Robots.h" in the local folder but will search for <foo.h> in the libraries. I need a few other pointers to how this mechanism works so I can fix my code.

Good links appreciated.

#include <foo.h> searches the libraries folder, along with a few other folders.

#include "foo.h" searches the local folder, then the rest of the include path (the libraries folder and others). But you need to understand that "local" is relative to the file that contains the #include directive. So if you have this:

{Sketchbook folder}
|_MySketch
| |_MySketch.ino
| |_Robot.h
|_libraries
|_MyLibrary
|_MyLibrary.h

and MyLibrary.h contains the line:

#include "Robot.h"

Then Robot.h will not be found because in this context "local" meant the MyLibrary folder, not the MySketch folder.

Thanks. That helps.

You mention "other" folders that the compiler searches. Is there any way to instruct it to include a specific folder in its search?

You could edit platform.txt and add a -I flag to the compilation recipes:

You can also specify the absolute path. For example:

#include "C:\Users\rhj4\Documents\Arduino\MySketch\Robot.h"