Can a Workbench sketch access resources outside of its root directory?

Hello –

I’m trying to share a header file between multiple Workbench projects. My file structure essentially looks like this:

| |
| |____src
| | |____SensorSwitch.ino
| |____SensorConfig.h
| |
| |____src
| | |____BaseStation.ino

Both SensorSwitch and BaseStation directories are project roots. Is it possible for the sketches in those directories to include the SensorConfig.h file in the Common directory? I know that I could just copy that header file to each project and include it, but that doesn’t strike me as being very DRY.

Also, will the suggestion in this article point me in the right direction, or is what I’m trying to do just something that’s not currently possible using Workbench?: c++ - VSCode not recognizing includes from includepath - Stack Overflow

Thank you.

Yes and no, and it depends on several things:

If you are building locally in Workbench, you can use to add the Common directory as an additional include path for the C++ compiler, at least in theory. It’s a little tricky to get working.

If you are building locally you can also use paths of the form:

#include "../Common/SensorConfig.h"

If you are building locally or in the cloud at least on Linux and Mac you can symlink (ln -s) the SensorConfig.h from the common directory into the src directory of SensorSwitch and BaseStation. In addition to working for both local and cloud, if you commit the symlink to Github, it does the right thing on clone (recreates the symlink instead of duplicating the file).

1 Like

Thanks so much for taking the time to respond @rickkas7. Creating symlinks was exactly what I needed to get this to work. :+1:

1 Like