fpiSTM wrote: ↑Wed May 05, 2021 9:07 am
...
In both case I have the build error. As you can see if the Arduino.h is included at sketch level it is not added twice (before #line1) in the converted sketch cpp file.
The only difference seems I'm on Windows but I think it is the same behaviour on Linux. So, maybe you should open an issue on Arduino side to tack this as it is mainly an Arduino IDE issue related to the way it builds.
I agree, this seems to be a build system bug in the Arduino IDE.
I am going to file an issue in the Arduino stable github, and I'll report back on whatever reply I get there. Thank you very much for your testing this strange bug.
EDIT
====
1. I took a long look at the Arduino Github (Arduino IDE Github is for version 2.0 which is still in Beta) at the open and closed issues, and problems with the placement of #include <Arduino.h> have been reported and there is an issue still open since 2017 or so.
2. I tested further and the compilation problem only occurs when I use the u8g2/u8x8 library. So the problem really involves an interaction between:
a. the Arduino CLI (which is where the .ino sketch is built),
b. the STM32 source wrapper, and
c. the u8g2/u8x8 library.
I don't really have the time to further research this complex issue and post on GitHub in three different projects, so for now I can only reiterate my initial warning:
If one is using the U8g2/u8x8 library in an STM32 project, DON'T #include <Arduino.h> explicitly. It is not needed and it will cause strange problems during compilation.
EDIT: I couldn't help it and ended up posting an issue in the u8g2 github, here:
https://github.com/olikraus/u8g2/issues/1486 and in the Arduino github, here:
https://github.com/arduino/Arduino/issues/11488