Misleading build error when using platformio vs Arduino IDE


#1

Hello,

I have a question regarding why I get different errors for the same issue in platform io and the Arduino IDE

The version of platformio I am using is 3.6.0a1 and compiling for a Teensy 3.6 board.

My platformio.ini looks like this

[env:teensy36]
lib_ldf_mode = deep
platform = teensy
board = teensy36
framework = arduino

and I have the following piece of code
#include <Arduino.h>
#include

std::vector v1(20);
std::vector v2(20);

void setup(){
v1.resize(100);
v2.resize(v1.size());
}
void loop(){}

When I build it using platformio using pio run I get the following error

Verbose mode can be enabled via -v, --verbose option
PLATFORM: Teensy > Teensy 3.6
SYSTEM: MK66FX1M0 180MHz 256KB RAM (1MB Flash)
DEBUG: CURRENT(jlink) EXTERNAL(jlink)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(deep) COMPATIBILITY(soft)
Collected 100 compatible libraries
Scanning dependencies…
No dependencies
Compiling .pioenvs/teensy36/src/wristmc.cpp.o
Linking .pioenvs/teensy36/firmware.elf
/home/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/5.4.1/…/…/…/…/arm-none-eabi/lib/armv7e-m/fpu/libc.a(lib_a-writer.o): In function _write_r':** **writer.c:(.text._write_r+0x12): undefined reference to_write’
collect2: error: ld returned 1 exit status
*** [.pioenvs/teensy36/firmware.elf] Error 1
========================== [ERROR] Took 2.24 seconds ==========================

but the same code build on the Arduino IDE outputs the following error

Compiling libraries…
Compiling core…
Using precompiled core
Linking everything together…
“/home/user/.arduino-1.8.5/hardware/teensy/…/tools/arm/bin/arm-none-eabi-gcc” -O2 -Wl,–gc-sections,–relax,–defsym=__rtc_localtime=1528735387 “-T/home/user/.arduino-1.8.5/hardware/teensy/avr/cores/teensy3/mk66fx1m0.ld” -lstdc++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -o “/tmp/arduino_build_766032/vector_test.ino.elf” “/tmp/arduino_build_766032/sketch/vector_test.ino.cpp.o” “/tmp/arduino_build_766032/…/arduino_cache_80447/core/core_teensy_avr_teensy36_usb_serial,speed_180,opt_o2std,keys_en-us_c5cdcebd6f74fa7c39a4ceb244d3917c.a” “-L/tmp/arduino_build_766032” -larm_cortexM4lf_math -lm
/tmp/arduino_build_766032/sketch/vector_test.ino.cpp.o: In function std::vector<int, std::allocator<int> >::_M_check_len(unsigned int, char const*) const': /home/user/.arduino-1.8.5/hardware/tools/arm/arm-none-eabi/include/c++/5.4.1/bits/stl_vector.h:1425: undefined reference tostd::__throw_length_error(char const*)’
collect2: error: ld returned 1 exit status
Error compiling for board Teensy 3.6.

In order to solve this error the following function in the std name space must be defined

namespace std{
void __throw_length_error( char const*e )
{
Serial.print(“Length Error :”);
Serial.println(e);
while(1);
}
}

The resulting code should look like this
#include <Arduino.h>
#include

namespace std {
void __throw_length_error( char const*e )
{
Serial.print(“Length Error :”);
Serial.println(e);
while(1);
}
}

std::vector v1(20);
std::vector v2(20);

void setup(){
v1.resize(100);
v2.resize(v1.size());
}

void loop(){}

Since I am not an expert on Embedded programming I would like to know why this mismatch is related to and if it might be a bug.

Thanks :slight_smile: