ArduinioSTL fails to compile

Status
Not open for further replies.

truth

Member
I'm using Visual Micro in VS 2019 and need std::map.
I successfully installed ArduinoSTL via the Add Library>Download and Install Arduino Library menu item.
I added <ArduionSTL.h> to my .ino.
Any ideas why I get the following errors when I compile?


Code:
Compiling debug version of 'LED Control' for 'Teensy 3.2 / 3.1'
ArduinoSTL.cpp: 79:2: warning: #warning "printf() will not be functional on this platform." [-Wcpp]
   #warning "printf() will not be functional on this platform."
 
WProgram.h:45: In file included from
Arduino.h*:6: from
ArduinoSTL.cpp:2: from
 
wiring.h: 48:76: error: 'enable_if' in namespace 'std' does not name a template type
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std*: enable_if<std::is_integral<T>::value >::type* = 0)
 
wiring.h: 48:85: error: expected ',' or '...' before '<' token
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std*: enable_if<std::is_integral<T>::value >::type* = 0)
 
wiring.h: 64:68: error: 'enable_if' in namespace 'std' does not name a template type
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std*: enable_if<std::is_floating_point<T>::value >::type* = 0)
 
wiring.h: 64:77: error: expected ',' or '...' before '<' token
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std*: enable_if<std::is_floating_point<T>::value >::type* = 0)
 
WProgram.h:45: In file included from
Arduino.h*:6: from
ArduinoSTL.cpp:2: from
 
wiring.h: 72:54: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:68: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:75: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:89: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: In function constexpr decltype (((a < b) ? (<expression error> > a) : (<expression error> > b))) min(A&&, B&&)
 
wiring.h: 73:18: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:32: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:39: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:53: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
wiring.h: At global scope
 
wiring.h: 76:54: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:68: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:75: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:89: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: In function constexpr decltype (((a < b) ? (<expression error> > a) : (<expression error> > b))) max(A&&, B&&)
 
wiring.h: 77:19: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:33: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:40: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:54: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
 
WProgram.h:45: In file included from
Arduino.h*:6: from
 
wiring.h: 48:76: error: 'enable_if' in namespace 'std' does not name a template type
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std*: enable_if<std::is_integral<T>::value >::type* = 0)
 
wiring.h: 48:85: error: expected ',' or '...' before '<' token
 long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std*: enable_if<std::is_integral<T>::value >::type* = 0)
 
wiring.h: 64:68: error: 'enable_if' in namespace 'std' does not name a template type
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std*: enable_if<std::is_floating_point<T>::value >::type* = 0)
 
wiring.h: 64:77: error: expected ',' or '...' before '<' token
 T map(T x, A in_min, B in_max, C out_min, D out_max, typename std*: enable_if<std::is_floating_point<T>::value >::type* = 0)
 
WProgram.h:45: In file included from
Arduino.h*:6: from
 
wiring.h: 72:54: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:68: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:75: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 72:89: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: In function constexpr decltype (((a < b) ? (<expression error> > a) : (<expression error> > b))) min(A&&, B&&)
 
wiring.h: 73:18: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:32: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:39: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 73:53: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
wiring.h: At global scope
 
wiring.h: 76:54: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:68: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:75: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: 76:89: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)) {
 
wiring.h: In function constexpr decltype (((a < b) ? (<expression error> > a) : (<expression error> > b))) max(A&&, B&&)
 
wiring.h: 77:19: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:33: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:40: error: 'forward' is not a member of 'std
   forward<A>(a) : std::forward<B>(b)
 
wiring.h: 77:54: error: expected primary-expression before '>' token
   forward<A>(a) : std::forward<B>(b)
Error compiling libraries
   Debug Build Error: This hardware might not support the default Visual Micro Debugger.
	If this project is using OTA/WiFi upload then please use the vMicro>Debugger menu to set the Serial COM and Remote port for the debugger.
	Otherwise switch the toolbar from 'Debug' to 'Release' and build again. 
		or switch off Automatic Debugging
		or configure the SoftwareSerial debugger option.
Debug build failed for project 'LED Control'
 
Last edited:
Perhaps I don't even need ArduinoSTL (anymore) but if I don't use it I get linker errors

=======================
Code:
Compiling debug version of 'LED Control' for 'Teensy 3.2 / 3.1'
 

Error linking for board Teensy 3.2 / 3.1
LED Control.cpp.o: In function std::_Rb_tree_iterator<std::pair<unsigned char const, LED> >::operator--()
Debug build failed for project 'LED Control'
stl_tree.h:220: undefined reference to std  _Rb_tree_decrement(std  _Rb_tree_node_base*)
 
LED Control.cpp.o: In function std::_Rb_tree_iterator<std::pair<unsigned char const, LED> > std::_Rb_tree<unsigned char, std::pair<unsigned char const, LED>, std::_Select1st<std::pair<unsigned char const, LED> >, std::less<unsigned char>, std::allocator<std::pair<unsigned char const, LED> > >::_M_insert_<std::pair<unsigned char, LED>, std::_Rb_tree<unsigned char, std::pair<unsigned char const, LED>, std::_Select1st<std::pair<unsigned char const, LED> >, std::less<unsigned char>, std::allocator<std::pair<unsigned char const, LED> > >::_Alloc_node>(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::pair<unsigned char, LED>&&, std::_Rb_tree<unsigned char, std::pair<unsigned char const, LED>, std::_Select1st<std::pair<unsigned char const, LED> >, std::less<unsigned char>, std::allocator<std::pair<unsigned char const, LED> > >::_Alloc_node&)
stl_tree.h:1540: undefined reference to std  _Rb_tree_insert_and_rebalance(bool, std  _Rb_tree_node_base*, std  _Rb_tree_node_base*, std  _Rb_tree_node_base&)
 
collect2.exe*: error: ld returned 1 exit status
 
This compiles and runs on a T3.2

Code:
#include <map>

std::map<int, std::string> myMap;

void setup()
{
    while(!Serial){}

    myMap.emplace(1, "Hello");
    myMap.emplace(2, "STL");

    Serial.println(myMap[1].c_str()); // Hello
    Serial.println(myMap[2].c_str()); // STL
}

void loop()
{
}

IF you add -lstdc++ to the linked libraries
 
Really appreciate the reply but doesn't work for me.
Doesn't even find .emplace()
Maybe it's a Visual Micro configuration problem.

Code:
#include <map>
#include <string>

std::map<int, std::string> myMap;

// the setup function runs once when you press reset or power the board
void setup() {
    while (!Serial) {}

    myMap.emplace(1, "Hello");
    myMap.emplace(2, "STL");

    Serial.println(myMap[1].c_str()); // Hello
    Serial.println(myMap[2].c_str()); // STL
}

// the loop function runs over and over again until power down or reset
void loop() {
  
}

Code:
Compiling debug version of 'Sketch1' for 'Teensy 3.2 / 3.1'
Using previously compiled file: C:\Users\xxx\AppData\Local\Temp\VMBuilds\Sketch1\teensy31\Debug\pch\Arduino.h.gch
 
Sketch1.cpp.o: In function std::_Rb_tree_iterator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator--()

Error linking for board Teensy 3.2 / 3.1
Debug build failed for project 'Sketch1'
stl_tree.h:220: undefined reference to std  _Rb_tree_decrement(std  _Rb_tree_node_base*)
 
Sketch1.cpp.o: In function std::_Rb_tree<int, std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::_Select1st<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::less<int>, std::allocator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_insert_node(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*)
stl_tree.h:2105: undefined reference to std  _Rb_tree_insert_and_rebalance(bool, std  _Rb_tree_node_base*, std  _Rb_tree_node_base*, std  _Rb_tree_node_base&)
 
Sketch1.cpp.o: In function void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag)
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)
basic_string.tcc:212: undefined reference to std  __throw_logic_error(char const*)
 
Sketch1.cpp.o: In function std::_Rb_tree_iterator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator--()
stl_tree.h:220: undefined reference to std  _Rb_tree_decrement(std  _Rb_tree_node_base*)
 
Sketch1.cpp.o: In function std::_Rb_tree_iterator<std::pair<int const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator++()
stl_tree.h:205: undefined reference to std  _Rb_tree_increment(std  _Rb_tree_node_base*)
 
collect2.exe*: error: ld returned 1 exit status
 
-lstdc++ has always been there as far as I can tell

boards.txt
.
.
.
teensy31.build.flags.S=-x assembler-with-cpp
teensy31.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx256.ld" -lstdc++
teensy31.build.flags.libs=-larm_cortexM4l_math -lm
 
Sorry, my answer was a bit short...
It is there but in the wrong place, move it to the end of the next line, then it should work.

Code:
teensy31.build.flags.S=-x assembler-with-cpp
teensy31.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx256.ld" 
teensy31.build.flags.libs=-larm_cortexM4l_math -lm [B][COLOR="#800080"]-lstdc++[/COLOR][/B]
 
Sorry, my answer was a bit short...
It is there but in the wrong place, move it to the end of the next line, then it should work.

Code:
teensy31.build.flags.S=-x assembler-with-cpp
teensy31.build.flags.ld=-Wl,--gc-sections,--relax,--defsym=__rtc_localtime={extra.time.local} "-T{build.core.path}/mk20dx256.ld" 
teensy31.build.flags.libs=-larm_cortexM4l_math -lm [B][COLOR="#800080"]-lstdc++[/COLOR][/B]

Vielen Dank!!!

1. I should have seen that!
2. It is in the wrong place in almost all the Teensy sections of boards.txt.
3. I'm guessing this is a bug in the teensyduino installer.
4. I wasted HOURS tracking this down...grrrrrrrrrr
 
Status
Not open for further replies.
Back
Top