I get this error when I attempt to include a file in a sub directory:
directories2:1: error: dir2\file2.h: No such file or directory
directories2.ino: In function 'void loop()':
directories2:12: error: 'func2' was not declared in this scope
If you create a library you can have a sub-directory called 'utility', but its seems not for a sketch, you'll have to keep all the sketch files together.
I guess memory is so small that flat file structures are acceptable.
Even if is weren't, dir2 is a directory in a directory. How is the preprocessor supposed to know what directory it is in?
You can use relative paths, like ".\dir2\file3.h" or absolute paths like "E:\here\that.h", but you can't expect the compiler to know "relative to" unless you define what "relative to" means (the . does that in the first example).
subdirectories:5: error: .\dir2\file2.h: No such file or directory
subdirectories.ino: In function 'void loop()':
subdirectories:17: error: 'func2' was not declared in this scope
subdirectories.ino:
#include ".\dir2\file2.h" //error: .\dir2\file2.h: No such file or directory
//#include "./dir2/file2.h" //same result with forward slash
void setup()
{
Serial.begin(115200);
Serial.println("in setup");
}
void loop()
{
Serial.println("in loop");
func2();
while(true) { }
}
Do you have any idea what . is when the code is compiled? It is NOT the directory that the sketch is in. If you can not be absolutely certain what . is, do not go that route. And, you can't, because the IDE creates a new build directory every time it builds.
You can't usefully put anything in a subdirectory to a sketch. All files in the sketch folder are copied to a Temp folder for compiling, but nothing in sub-folders.
You could put an include file in another directory and use an absolute path, but I would really not recommend it.
I spent some time trying to find ways round the "flat" restriction in the Arduino IDE, but decided don't fight it, live with it
An alternative is to use a different IDE , like Eclipse, if you don't mind losing Arduino IDE compatibility.
If your project is big enough to want subdirs, then code it as a library or
libraries.. Its probably made of several parts anyway, one or more of
which you may want to reuse in future sketches.