Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
STLport for AVR Microcontrollers
Yes, Virginia, there is a C++ standard library suitable for use on AVR microcontrollers, including the Arduino, and this is the (most complete, tested, and liberally-licensed) one!
For use with Arduino, download this auto-generated zip file of the latest STLport-5.2-arduino-installed branch, and unzip it.
You'll see it contains a directory with a complicated name.
The task now is to rename the innermost "complicated-named" directory to
Move Into Place
Now, you need to get that
stlport directory into your "sketchbook" in the libraries directory. On Windows, the default sketchbook is in
My Documents\Arduino - you may need to make a
libraries directory within there if one doesn't already exist. After moving the directory, you'll end up with something like this.
Or, for the Git-savvy...
You can clone the
STLport-5.2-arduino-installed branch into your sketchbook's libraries directory, into a directory named
stlport - for example, on Linux:
git clone -b STLport-5.2-arduino-installed https://github.com/vancegroup/stlport-avr.git ~/libraries/stlport
More info below and at Arduino-Style Build Systems
This work is based on the upstream STLport project and its git repositories. Modified version of
master (in this repo as STLport-master-avr) and
STLport-5.2 (in this repo as STLport-5.2-avr) have been made to allow compilation with the avr-libc/
avr-gcc toolchain. Emphasis has been on the header-only aspect of the library, however, the standard build system does work to a degree, with e.g. these commands:
./configure --target=avr make release-static
In addition, to allow use with the Arduino IDE, the headers as well as a dummy header have been exported to branches suitable for use as Git submodules in a Git-managed sketchbook, or directly as Git repos in an unmanaged sketchbook. The branches are named STLport-master-arduino-installed and STLport-5.2-arduino-installed respectively. Note that if you are using the actual Arduino IDE to build, you must use the 5.2 version. The master version is made available if you're using an Arduino-inspired build system such as Arduino-Makefile that allows you to pass additional compiler flags. (See below for details.)
How to choose a branch?
Simple: There are two different stability levels corresponding to two different C++ standards. Then, you just need to determine if your build is Arduino-like or not. You'll end up with a branch name like "STLport-version-arduinovariantornot".
masterbranch/version, aka the future STLport 6.0, is a C++11 standard library. If that is what you want, and your version of
avr-gcccan handle it (be sure to pass
-std=gnu++0xin with your project's
CXXFLAGS), use the branches based on the version
master. Note that a number of features (
thread, etc) are disabled due to the lack of an underlying operating system and/or libc with the required features, so you won't get the full C++11 standard library. Keep in mind that the master branch is apparently an unreleased work in progress - I haven't talked with upstream to find out how "complete" they consider it.
5.2branches are based on a stable release branch. If you don't need C++11 support, and particularly if you need to support the Arduino IDE (where you can't pass additional compiler flags), stick with these branches. They are named with
5.2in the version field as described above.
If you're using an Arduino-like build system, the variant you want ends in
arduino-installed. See Arduino-Style Build Systems for more info.
If you're not using anything to build that requires an Arduino-like layout, you've got choices between
avr. See Other AVR Build Systems for details.
Due to the AVR's lack of an operating system, as well as its embedded-focused (and thus limited) libc, a number of features in upstream STLport are disabled when used on an AVR. The limitations of this modified version with respect to upstream or a desktop standard C++ library include:
- No multi-threading support.
fstreamand related code.
- No default streams (
std::coutand friends) created. (If you use any streams, you'll need to compile library files beyond the headers.)
- Disabled locales support and wide character types.
long doublesupport. (Note that as of this writing
doubleon AVR is actually
- Disabled exceptions and RTTI support (based on typical invocations of
Note that all these modifications have been done in such a way that they could be merged back upstream (by adding a system config header and defining configuration macros), and so that they do not affect the functionality of the same STLport tree compiled or used on a different architecture.