fix(espidf): drop textual #include "sketch.ino.cpp" in main wrapper
Now that main/CMakeLists.txt globs every *.cpp/*.c into SRCS (commit
27c9a28 — needed so multi-file Arduino projects link), sketch.ino.cpp
is compiled as its own translation unit. The template main.cpp's
`#include "sketch.ino.cpp"` is left over from when SRCS only named
main.cpp — back then we had to pull the user code into main.cpp's TU
to get it compiled at all.
With the glob in place, keeping the include re-defines setup() and
loop() in main.cpp's TU AND in sketch.ino.cpp.obj, so the linker dies
with "multiple definition of `setup'". Replace the include with a
forward declaration and let the linker resolve setup()/loop() from
sketch.ino.cpp.obj. Matches arduino-cli's per-file compile + auto-link
model, and frees pure-C++ multi-file sketches to put helper TUs in
their own .cpp files without textual-include hacks.
Repro: robot-desktop-eyes after the glob fix (#13 rebuild) — compile
got past resolve+compile and into link, where multi-def of setup()
would have appeared on the next attempt. This commit closes the loop.
This commit is contained in:
parent
27c9a2853d
commit
21791a8237
|
|
@ -1,12 +1,22 @@
|
||||||
/**
|
/**
|
||||||
* Arduino-as-ESP-IDF-component wrapper.
|
* Arduino-as-ESP-IDF-component wrapper.
|
||||||
*
|
*
|
||||||
* The build system copies the user's .ino sketch as "sketch.ino.cpp" into
|
* The espidf_compiler writes the user's entry .ino as "sketch.ino.cpp"
|
||||||
* this directory. initArduino() initializes the Arduino runtime (GPIO,
|
* into this directory and drops every helper .h/.cpp alongside it.
|
||||||
* Serial, WiFi, etc.) and then we call the user's setup()/loop().
|
* The CMakeLists.txt globs *.cpp/*.c into SRCS, so each TU compiles
|
||||||
|
* standalone — setup() and loop() are defined exactly once across the
|
||||||
|
* link (in sketch.ino.cpp) and we just call them from app_main() with
|
||||||
|
* a forward declaration.
|
||||||
|
*
|
||||||
|
* Note: do NOT switch this back to `#include "sketch.ino.cpp"` — the
|
||||||
|
* textual include would re-define setup()/loop() inside this TU as
|
||||||
|
* well, fighting the standalone sketch.ino.cpp.obj for the symbol
|
||||||
|
* and tripping the linker with "multiple definition of `setup'".
|
||||||
*/
|
*/
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "sketch.ino.cpp"
|
|
||||||
|
void setup();
|
||||||
|
void loop();
|
||||||
|
|
||||||
extern "C" void app_main(void) {
|
extern "C" void app_main(void) {
|
||||||
initArduino();
|
initArduino();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue