Skip to content
rpavlik edited this page Sep 19, 2012 · 14 revisions

STLport for AVR Microcontrollers

This repo 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.

  • The future STLport 6.0 is a C++11 standard library, so if that is what you want, and your version of avr-gcc can handle it (be sure to pass -std=gnu++11 or -std=gnu++0x in with your project's CXXFLAGS), use the branches based on master. Note that a number of features (chrono, 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.

  • On the other hand, if you don't need C++11 support (k), and particularly if you need to support the Arduino IDE (where you can't pass additional compiler flags), stick with branches based on the 5.2 stable branch.

Non-Arduino build system

You can use the library in a few ways:

  • If you only need the headers, you can just use the -arduino-installed variants of branches. They're just the headers, moved up to the top level, with a harmless dummy header added for the sake of the Arduino IDE. Just add your checkout/submodule path to your compiler include path.

  • You can use the -avr branches and build a static library and headers to use in your project.

  • You can use the -avr branches but build the desired sources within your own build system along with your own sources.

Note that you might need to provide files like Arduino's new.h and new.cpp in your build system and include path for things requiring placement-new to work.

Arduino-like builds

If you use the Arduino IDE or a similar system, you'll have a directory known as your "sketchbook." (On Linux, this defaults to ~/sketchbook.) Within the sketchbook, libraries can be placed in the libraries subdirectory, with a very specific naming system: They must have no dashes in them, and they must contain a header named _directoryname_.h. In the case of STLport, you'll want to use the branches ending in -arduino-installed, and clone them into a subdirectory named stlport as they already include the stlport.h dummy header. For example,

mkdir -p ~/sketchbook/libraries
git clone -b STLport-5.2-arduino-installed https://github.com/vancegroup/stlport-avr.git ~/sketchbook/libraries/stlport

I tend to keep my sketchbook in Git, so for me, I add this directory as a submodule, which works pretty much the same.

cd MYSKETCHBOOKROOT
git submodule add -b STLport-5.2-arduino-installed https://github.com/vancegroup/stlport-avr.git libraries/stlport

In your project, then, at the top of the main .ino file, add the line

#include <stlport.h>

to trigger the Arduino IDE to add the stlport directory to the include path. (The header is empty and serves only this indicating purpose: if you want to use any of the headers, you can then use them directly.) If you're not using the Arduino IDE, it won't hurt to add this line, but you might also need to indicate to your build system that you're using the stlport library.

Clone this wiki locally