Teensy 3.6 linking fails for stdc++ containers

ardnew

Member
With Arduino 1.8.10 just becoming available, I couldn't figure out why my sketch was failing to link and remembered making an update to the board definitions in Arduino 1.8.9 for Teensy 3.6. Thought I would post my fix here for posterity.

To recreate the problem, on a Teensy 3.6, create a list:

Code:
#include <list>
std::list<Blah> myList;

Probably add some list operations, and try to build.

In my particular project, it fails with the following error:

Code:
/tmp/arduino_build_679496/sketch/cathys-sensor.ino.cpp.o: In function `void std::__cxx11::list<Infrared_Diode, std::allocator<Infrared_Diode> >::_M_insert<Infrared_Diode const&>(std::_List_iterator<Infrared_Diode>, Infrared_Diode const&)':
/home/andrew/.bin/arduino-1.8.10/hardware/tools/arm/arm-none-eabi/include/c++/5.4.1/bits/stl_list.h:1764: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/tmp/arduino_build_679496/sketch/cathys-sensor.ino.cpp.o: In function `std::__cxx11::list<Infrared_Diode, std::allocator<Infrared_Diode> >::_M_erase(std::_List_iterator<Infrared_Diode>)':
/home/andrew/.bin/arduino-1.8.10/hardware/tools/arm/arm-none-eabi/include/c++/5.4.1/bits/stl_list.h:1774: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
collect2: error: ld returned 1 exit status

To fix, I only had to move the stdc++ linker flag from one line to another. In hardware/teensy/avr/boards.txt:

Code:
teensy36.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk66fx1m0.ld" -lstdc++
teensy36.build.flags.libs=-larm_cortexM4lf_math -lm

Should be changed to:

Code:
teensy36.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk66fx1m0.ld" 
teensy36.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++
 
Back
Top