Skip to content

Arduino Style Build Systems

rpavlik edited this page Sep 19, 2012 · 1 revision

Installing the library

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 to match the directory with .h appended (DIRECTORYNAME.h).

To use STLport, you'll want to use the branches ending in -arduino-installed, and clone them into a subdirectory of libraries named stlport. The headers are at the top level, and they already include the stlport.h dummy header. For example, the following clones into the default sketchbook location on Linux, and checks out the 5.2 version right away:

mkdir -p ~/sketchbook/libraries
cd ~/sketchbook
git clone -b STLport-5.2-arduino-installed https://github.com/vancegroup/stlport-avr.git 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 MYSKETCHBOOKDIRECTORY
git submodule add -b STLport-5.2-arduino-installed https://github.com/vancegroup/stlport-avr.git libraries/stlport

Using the library

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

#include <stlport.h>

This line will trigger the Arduino IDE to add the stlport directory to the include path and compile any sources it finds in the stlport directory (it doesn't recurse). The header is empty and serves only this single purpose. To use the standard library, then, you can include them just as you would on a desktop machine - no need to preface the header names with stlport. For example, here's a silly sketch to show you what you can do:

#include <stlport.h>
#include <vector>
#include <cstdint>

std::vector<std::uint8_t> vec(10, 0);

void setup() {
    vec[0] = 5;
    vec[3] = 2;
    Serial.begin(115200);
}

void loop() {
    for (std::vector<uint8_t>::iterator it = vec.begin(), e = vec.end(); it != end; ++i) {
        Serial.println(*it);
    }
    sleep(2000);
}

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 (in a Makefile or similar) that you're using the stlport library.

Clone this wiki locally