I have several #define statements in a library .h file that need to be different for different sketches. But I can't think of a way to change them except by editing the library. I could modify the library so that these configurations are selectable at run-time but this costs significant code and some memory. And I won't need to change them during run-time.
Is there any way to set configuration parameters at compile time in a library without editing the library itself?
You could move the #defines to a separate file and #include that in the library. Still need to edit per sketch, but avoids the risk of accidentally changing something else in the library.
That's still just one file that has to be edited each time I compile a different sketch. I want a separate file for each sketch. Is this not possible in Arduinoland?
Is there an #include directive that causes the compiler to search the folder of the current sketch?
jboyton:
That's still just one file that has to be edited each time I compile a different sketch. I want a separate file for each sketch. Is this not possible in Arduinoland?
Is there an #include directive that causes the compiler to search the folder of the current sketch?
couldn't you just have one #define that you put at the top of your sketch
couldn't you just have one #define that you put at the top of your sketch
No, because the header file included in the sketch would see that #define value defined in the sketch, but when the header file is included in the library, the #define from the sketch is not visible. It's in another compilation unit.
What some development environments do is let you define "defines" which then get passed to every compilation unit. For example, Arduino does that by implication when you select a board type, but it doesn't let you supply user-defined defines. Perhaps make a suggestion to them on GitHub?