Tuesday, October 23, 2012

C++ STL for Arduino

It may not be obvious, but Arduino is programmed in C++.

However, the core libraries do not support the Standard Template Library, which has (in my opinion) indispensable support for generic containers like vector, list, map, and so on.

Well, some kind person did a straight port of the uClibC implementation of STL, and it is available here:

https://github.com/maniacbug/StandardCplusplus

The instructions are pretty clear, but I will summarize:
  • Open up your Arduino IDE, go to preferences, and locate your sketchbook (details here: http://www.arduino.cc/en/Guide/Environment). On my Ubuntu 12.04 machine, it is /home/slogan/sketchbook. Chdir to that location and then type:
$ mkdir -p libraries
  • Download the StandardCplusplus tarball into the libraries directory you just created, and unpack it with
$ tar -zxvf file (where file is the name of the tarball)
  • Exit arduino IDE if running, then restart.
  • Go to File->Examples/StandardCplusplus and select one of the examples, and compile it.
I haven't done any testing but given it is a straight port from uClibC I'm not expecting surprises. This is a huge plus for me, because other than occasionally using Boost (most recently for regex), the STL containers are essential for my style of C++ programming.

Enjoy.



No comments:

Post a Comment