Trouble using std::string

Status
Not open for further replies.

SnowMB

New member
Hello,

I'm tinkering with a Teensy 3.6 and c++ and I'm wondering about the following:

It's perfectly fine in my project to use std::vector, since the toolchain includes libstdc++. But when trying even the simplest things with for example std::string and std::deque or even some operations with a std::unique_ptr, I get linker errors.

Consider this simple example:

Code:
#include <string>

std::string str = "abc";

void setup() {
}

void loop () {
}

Compiling works fine but linking results in this error:

Code:
/home/marc/.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

What am I missing here? What do I have to do, to get this elements of the c++ standard library to work?


I found some guidance in another forum post (https://forum.pjrc.com/threads/23467-Using-std-vector?p=69787&viewfull=1#post69787), but unfortunately modifying the boards.txt file has no effect.
 
your missing includes
for deque i think you need to include <deque> or <queue> one of those for it to work..
havnt played with unique_ptr
 
Yeah, of course I used the includes accordingly. But, as I said, compiling works fine. The error occurs in the linker. It has been really hard to narrow down the lines causing the error.

Just try the above example with a default Arduino + Teensyduino installation. I did nothing fancy.
 
Status
Not open for further replies.
Back
Top