5

I was going to update this question but I thought that this was different.

I have been trying to get std::vector to work with the latest Arduino. I have tried downloading several libraries found online but I can not get one of them to compile correctly. So here is my question, does anyone CURRENTLY know of a Arduino STL Library that is working?

StandardCplusplus: As stated above I tried to use this library but run into problems with the new/delete functions.

Andy Brown's AVR-STL Library doesn't even seem to come close to compiling.

If anyone has a working copy of these two I would love to have a copy or if you can tell me how to get them to compile. Otherwise I really need to find a way to get Vectors working, does anyone have any ideas?

Edit

I didn't want to answer this question so it is still active as I am sure there will be additions to this. Anyways I FINALLY got a library to work (for now, so far). I downloaded the StandardCplusplus library and found that in order to get any of the stl functions to work you have to add an include to the "StandardCplusplus.h" file before EVERY use, not just in the first file as stated in the Wiki on the Project page.

So I was able to get vectors to work using the following:

#include "StandardCplusplus.h"
#include <iterator>
#include <vector>

vector<int> test;

void setup(){
   Serial.begin(57600);

   test.push_back(1);
   test.push_back(2);
   test.push_back(3);
   test.push_back(4);
}

void loop(){
   for (int i = 0; i < test.size(); i++){
      Serial.println(test[i]);
   }
}

I would still like to know of other working STL Libraries as it seems that there are tons of outdated and old libraries out there.

  • I was wondering the same. At school, we once used the "GNU-GCC" toolchain to cross-compile for AVR targets. We could use all fancy vector & queue things, but I'm uncertain if it required any additional steps (which I forgot). – Paul May 16 '16 at 19:40
  • You may try the original C++ libraries? They would be poorly optimized though, but I'm curious if they will perform reasonable. C++ should be portable to other platforms, though, microcontrollers do have their limits. – Paul May 16 '16 at 19:44
  • @Paul I really am not sure were to start trying to port the original libraries, I am pretty new to Arduino and AVR Programming and I am still feeling out the limitations. I do know however that other people have been successful in using vector and other STL functions. I just have to figure out how to do it repeatably. Another thing I noticed when using the above library I get intermittent compiler errors so I am thinking that there are still issues. – Andy Braham May 17 '16 at 12:17
  • 2
    You are probably having a hard time finding good libraries because dynamic memory is rarely used on micro controllers with such small amounts of RAM – BrettAM May 17 '16 at 16:43
  • 1
    @AndyBraham. Those old 286 machines had MMU, multilevel interrupts, 1 MB addressable memory (DOS, real mode), DMA transfer, 16 bits registers, separate address and data buses and FPU (via co-processor). – user31481 Oct 20 '17 at 12:11
5

I maintain an Arduino plugin that's a port of uClibc++ (just like the defunct StandardCplusplus library). It's available in the Arduino library manager for Arduino versions 1.6.10 and higher. It's called ArduinoSTL.

  • Thank you for the suggestion but I am running into a problem with your library. I simply tried to include the "ArduinoSTL.h" file into a blank sketch but I receive a error in iterator.cpp "The system cannot find the file specified.". Any idea what file might be missing from my setup? I am using Eclipse Neon – Andy Braham Nov 6 '16 at 13:49
  • You must include it via Arduino's GUI Sketch -> Include Library -> ArduinoSTL. If it's not in the list you can install it from the built-in library mager: Sketch -> Include Library -> Manage Libraries... – Michael Matera Feb 14 '17 at 4:06
  • Pity there's no C++11. Your <type_traits> header is lacking great many functions. – Violet Giraffe Jan 25 '18 at 6:31
-1

pay you attention which kind of arduino do you use. it can compile for Mega but not for Leonardo for example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.