Hi,
It seems to me that during the ‘.ino’ conversion phase the ‘#include’ directives aren’t processed (because of ‘-fpreprocessed’), and if a ‘#if’ conditional block relies on a symbol defined in an include, then it’ll be evaluated incorrectly.
In fact, all ‘#if’ lines are just skipped, and the content of their conditional blocks evaluated anyway, causing a lot of ‘warning: redefined’ warnings.
The compilation itself handles them well (otherwise variable definitions would clash), but those warnings still trigger false alarms.
To reproduce, we need 2 files, one include to define a symbol in, and a main file to use that symbol in a #if
config.h:
#define PRODUCT_VARIANT 42
//#define PRODUCT_VARIANT 43
main.ino:
#include "config.h"
#if PRODUCT_VARIANT == 42
#define GPIO_PWM 4
int something[256];
#endif // PRODUCT_VARIANT == 42
#if PRODUCT_VARIANT == 43
#define GPIO_PWM 12
char something[256];
#endif // PRODUCT_VARIANT == 43
void setup() {
}
void loop() {
while (true) {
}
}
And this is what it generates (pio run -v
):
...
xtensa-lx106-elf-g++ -o "/tmp/test/src/main.ino.cpp" -x c++ -fpreprocessed -dD -E "/tmp/tmpTMwbaM"
/tmp/test/src/main.ino:9:0: warning: "GPIO_PWM" redefined [enabled by default]
# define GPIO_PWM 12
^
/tmp/test/src/main.ino:4:0: note: this is the location of the previous definition
# define GPIO_PWM 4
^
...
I’like to keep my builds warning-free, so any suggestions are welcome.