I have a basic project targeting Arduino Mega board [1] that seems to stop compiling once the source code reaches a certain “size”.
In the following function [2],
bool hasAnotherLightPressed(int const led) {
for (int i = 0; i < LED_COUNT; i += 1) {
if (i != led && board::isPressed(i)) {
// Serial.print("<? ");
Serial.println(i);
return true;
}
}
return false;
}
if I uncomment the line Serial.println(i)
, the compilation starts throwing errors like the following:
/tmp/ccrn2Vp1.ltrans1.ltrans.o:(.rodata+0x30): undefined reference to ‘Game<snake::GameState>::initState(snake::GameState&)’
/tmp/ccroduzk.ltrans1.ltrans.o:(.rodata+0x32): undefined reference to ‘Game<snake::GameState>::copy(snake::GameState const&, snake::GameState&)’
Commenting back the line resolves the compilation error.
I can uncomment the line and go around in the code removing other Serial.print
, or bodies of some methods, and the code starts compiling again.
After a successful compilation, I got the following report:
RAM : [ ] 4.9% (used 404 bytes from 8192 bytes)
Flash: [ ] 3.0% (used 7590 bytes from 253952 bytes)
It does not seem that the whole program is that big, but still, the issue seems related to the amount of code I have.
Finally, I reproduce the issue with the latest PIO on two distinct machines (one Mac and a Linux PC).
Sorry for not having identified a much simpler case to reproduce the issue.
Note that the same error initially appear in the project, without any Serial, after I added a new class.
Thanks for any lead on that issue.
[1] https://gitlab.com/kineolyan/guak-a-mole/-/tree/compilation-error/guak-a-box
[2] https://gitlab.com/kineolyan/guak-a-mole/-/blob/compilation-error/guak-a-box/src/simon.cpp#L109-121