Having a common hardware include file amongst multiple projects without symlinks

Howdy,

I have this set of example code that all rely on a common include file that contains hardware definitions.

For now, I solved it like this:

neomatrix_config.h is a symlink to ../neomatrix_config.h
that way, I can change that include/config file, and all the demos get the new one.

This library has the same need:

Adafruit demos that refer to a display with specific configs and pins, have the same need too.

What is the best way to use a common config file for all such demos without using symlinks, as symlinks work great, except on windows where they do not work at all.

I could have some config.h file that then includes "../config.h" but I'm not sure the arduino IDE will be super happy with that, or if there is some other/better way.

Thanks.

includes "../config.h"

--> that won't work as the IDE makes a copy of the sketch folder in a temp space and then tries to compiles. at that point in time the .. is no longer what you thought it would be.

You could have a "pseudo library" in the library folder that will define the configuration and include it in all sketches (or the library itself)

J-M-L:
--> that won't work as the IDE makes a copy of the sketch folder in a temp space and then tries to compiles. at that point in time the .. is no longer what you thought it would be.

You could have a "pseudo library" in the library folder that will define the configuration and include it in all sketches (or the library itself)

Thanks J-M-L:
you are correct about the "include ../config.h" being a problem in the temporary build directory, and I was kind of wondering how my ../config.h symlink is working, but it is. I guess the IDE copies all the files and dereferences the symlink, copying the file it points to instead, so it works.
As you said, making a library that contains the config file and including it as a lib, would work, but it seems a bit weird, especially as the config file you're now referring to, is not in your sketch build dir anymore but in a completely different location.
If only symlinks could work on windows, that seems like it would be the best answer.
Seems that windows supports them on ntfs, but my guess is that git is unable to create them, so when the source is unpacked/retrieved, they don't show up and then things don't work.

If only symlinks could work on windows, that seems like it would be the best answer.

I'm using MacOS and Linux :slight_smile:

J-M-L:
I'm using MacOS and Linux :slight_smile:

Yeah, we're on the same page here :slight_smile:
Honestly I personally use symlinks because they work, and well, people on windows, sorry, it's not like windows didn't have 20 years to make this work better (technically, I read they work without administrator privileges on recent windows 10, but that's so late that it's not really useful)
Anyway, I was trying to make my lib and code work for everyone without making life suck more for me. I settled on symlinks which work great for my use case, but it's not a real solution for all.
From what you're saying it sounds like there may not be one. Oh well...

I've seen some libraries (a touch screen if I remember correctly) using a config file that you edit once and keep it there in the library folder so that all your projects would use the same configuration

alternatively, make that a call to the constructor or begin() of your library if it's a class and you can pass a configuration structure