arduino / arduino/ArduinoCore-sam
Linker error: undifined reference to std::__throw_length_error() when using vectors
- Dominant language
- HTML
- Stars
- 91
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
Whenever the C++ vector is used, linker shows error of not finding function:
```
sketch\vector_test.ino.cpp.o: In function `std::vector >::_M_check_len(unsigned int, char const*) const':
c:\users\ewing\appdata\local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\arm-none-eabi\include\c++\4.8.3\bits/stl_vector.h:1339: undefined reference to `std::__throw_length_error(char const*)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Due (Programming Port).
```
To reproduce: vector_test.ino
```C++
#include
#include
std::vector _test_v;
void setup() {
SerialUSB.begin(115200);
Serial.begin(115200);
Serial.println("=========Start Vector test==========");
_test_v.push_back(5);
Serial.print("element1: ");
Serial.print(_test_v[0]);
Serial.print("size: ");
Serial.print(_test_v.size());
delay(2000);
}
void loop() {
}
```
More info and workaroud: https://forum.arduino.cc/index.php?topic=319795.0
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the vector_test.ino reproduction and build it for the Arduino Due using the arm-none-eabi-gcc 4.8.3 toolchain shown in the error. Trace the link step around std::__throw_length_error and compare it with the documented forum workaround. Done means the sketch links successfully and the vector operations run without the undefined-reference error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100