undefined reference to `_sbrk'

Status
Not open for further replies.

kid1000002000

New member
Hi, working on a project and I think I've isolated an issue. Can anyone get the pasted code to compile? I'm on a teensy 3.2 compiling on arch linux. Using Arduino IDE 1.8.5, Teensy 1.4.1. Happy to compile at the CLI if it would help.

Code:
#include <vector>
#include <string>                                                                                                                                                                              

int main() {
    std::vector <std::string> myVector;
    myVector.push_back("stringA");
    return 0;
}

Traceback:
Code:
/usr/share/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status
Error compiling for board Teensy 3.2 / 3.1.
 
Last edited:
This compiles without any errors.


Code:
#include <vector>
#include <string>   

void setup() {
    std::vector <std::string> myVector;
    myVector.push_back("stringA");
}

void loop() {

}
 
Thanks Paul, your reply was way more than I had hoped for. Looks like I simplified too much for the forums. How about this time?

Code:
#include <vector>
#include <string>

class SubclassA {
    public:
        std::vector <std::string> options;
        SubclassA(std::vector <std::string> options0);
};

SubclassA::SubclassA(std::vector <std::string> options0){
    this->options = options0;
}

void setup() {
    std::vector <std::string> myVector;
    myVector.push_back("stringA");
    SubclassA b = SubclassA(myVector);
}

void loop() {

}
 
nope - prior output not posted - this shows here:
Linking everything together...
"T:\arduino_1.8.5_142\hardware\teensy/../tools/arm/bin/arm-none-eabi-gcc" -O2 -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=1529516591 "-TT:\arduino_1.8.5_142\hardware\teensy\avr\cores\teensy3/mk66fx1m0.ld" -lstdc++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -o "T:\TEMP\arduino_build_997685/StrinVector_jun20b.ino.elf" "T:\TEMP\arduino_build_997685\sketch\StrinVector_jun20b.ino.cpp.o" "T:\TEMP\arduino_build_997685/core\core.a" "-LT:\TEMP\arduino_build_997685" -larm_cortexM4lf_math -lm
T:\TEMP\arduino_build_997685\sketch\StrinVector_jun20b.ino.cpp.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag)':

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.tcc:219: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned int&, unsigned int)'

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.tcc:212: undefined reference to `std::__throw_logic_error(char const*)'

T:\TEMP\arduino_build_997685\sketch\StrinVector_jun20b.ino.cpp.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1170: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/basic_string.h:1170: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

T:\TEMP\arduino_build_997685\sketch\StrinVector_jun20b.ino.cpp.o: In function `__gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned int, void const*)':

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\ext/new_allocator.h:102: undefined reference to `std::__throw_bad_alloc()'

t:\arduino_1.8.5_142\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\ext/new_allocator.h:102: undefined reference to `std::__throw_bad_alloc()'

collect2.exe: error: ld returned 1 exit status
 
Status
Not open for further replies.
Back
Top