I was messing around with code the other day and I came upon a weird compilation error. If I compiled code using std::vector, compilation was successful if I optimized for Faster, Fastest, or Smallest Code. Compilation failed if optimized for Fast, or Debug. The proof-of-concept below will demonstrate the failure for Fast or Debug and succeeds for Faster, Fastest or Smallest Code
Code:
/*
vector_error_poc
When set for Optimize: Faster, or Fastest, or Smallest Code <-- compilation successful
When set for Optimize: Fast or Debug <-- compilation fails
c:/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/armv7e-m/fpu/fpv5-d16\libgcc.a(unwind-arm.o): In function `get_eit_entry':
unwind-arm.c:(.text+0x134): undefined reference to `__exidx_end'
unwind-arm.c:(.text+0x138): undefined reference to `__exidx_start'
*/
#include <vector>
using std::vector;
vector<uint16_t> testArray;
const uint8_t led = LED_BUILTIN;
void setup()
{
while(!Serial);
pinMode(led, OUTPUT);
testArray.push_back(12345);
Serial.println(testArray[0]);
}
void loop()
{
bool ledState = !digitalRead(led);
digitalWrite(led, ledState);
delay(ledState?25:975);
}
The errors are typical of STD library errors, but why does compilation only fail for Optimize: Fast or Debug?