For this project, I have a number of very, very similar sketches. Basically, they share everything except a #define for a module name. So I moved the code into a separate file to include it into my sketches, which then should look like:
This does not work - the sketch does not find the "Master.cpp" file wich definitely is in the parent directory.
If I softlink the Master.cpp into the sketch directory, it tries to compile both the sketch and the Master.cpp file, and fails (Obviously, an .ino file includes something that I cannot see as a user).
If I softlink the file into the sketch directory as "Master.h", and use
#define MODULE_NAME "Module1"
#include "Master.h"
it works.
So while I have a working solution, why does #include "../Master.cpp" not work?
I just tried #include "../Master.hpp", #include "../Common/Master.h", and #include "../Common/Master.hpp", and none of them work. And yes, the files are there, they are acccessible, valid, etc. Always "Compilation error: (Filename incl. relative path as in the #include statement) No such file or directory".
Could you share a picture or something to show us were is located the file you wanna use and were is the project saved? Maybe the paths to the files are enough for us to tell
Yes, it fails, because Arduino IDE does not compile your code. It copy it somewhere to to temp directory and compile that copy (as can be seen, if you turn compiler messages to be visible).
And if the IDE did not copy all related files there too, then the related files are missing in the compile time.
(Just for test I moved all *.h from root of project 3 level of directories down and used in all related includes ../../../ as prefix and it normally compiled without problem.)
That would not solve the issue. What currently is the "LandingPad" directory and "LandingPad.ino" should be the "LandingPad1" directory with a "LandingPad1.ino", next to a "LandingPad2" directory with a "Landingpad2.ino", etc. They all share "Network.h" (with the SSID, the password, the MQTT server and port), and the "LandingPad.h" (which is the brain of the operation). The "LandingPad2.ino" would be nearly identical with the "LandingPad1.ino" except for the definition of "MODULE_NAME".
About using a "sane building systems instead of Arduino IDE" - I tried to build this with the RPi Pico SDK, but it was a bigger build system catastrophe than this here. Apart from their horrible MQTT implementation...
At this point, I can say that the soft link variety works for me. I was just wondering why relative paths outside the Sketch directory don't work as expected. If the IDE copies stuff around without thinking, this would explain the issue.
I think, that making the scr directory somewhere and making link named "src" in your project directory (where the link itself will be with full path, not relative) may work.
As for using build scripts, I'll be using makefiles on the long run with "arduino-cli compile --export-binaries" (and all the other options needed for it to actually build something) and then create the UF2 files from there into a separate directory for installation. For experimenting with the individual boards, the IDE is more than sufficient, and amazingly simple, if not too simple in some places (Like WTF does it not save project related preferences in the sketch directory like Board, Port, Programmer, etc)
I don't plan to add extra layers of complication to the whole thing. I now know that #include "../" does not work, and that I have to softlink the modules I need into the sketches. The main goal - that I can reuse and recycle the code has been reached.
I don't think that "without thinking" is an accurate description. You are simply trying to do something that the IDE is not designed for, and which there is no reason for it to be designed for.
Arduino libraries are the mechanism by which code is shared between multiple sketch projects. If you use the established mechanism, you will find that Arduino IDE works just fine. If you try to invent your own non-standard equivalent of that mechanism, then you should not be surprised to find that it doesn't work.
I use C compilers for about 30 years now, and this is the first time ever where I encounter an IDE where this simple, standard kind of behavior does not work. I never had reason to suspect that the IDE copies my sources to somewhere else before compiling it. Now that I know what to expect I can work with it, but it is not something to be expected - of all the tens of different C IDEs over a dozen or more platforms, the Arduino IDE is the first showing this rather odd and unexpected behavior.