Real C++ with Arduino

Expertise Solutions pushed fixes to libstdc++v3 in GCC upstream to fix problems with the STL in Arduino microcontrollers (and other 8-bit microcontrollers).

We will show you how to compile GCC with STL support enabled and how to use them in your applications.

First you create a directory to download and compile everything:

$ mkdir avr-build
$ cd avr-build

Installing avr-binutils

If you use Ubuntu, you can just install avr-binutils with:

$ apt-get install avr-binutils

And if you use Arch Linux, you can install avr-binutils with:

$ sudo pacman -S avr-binutils

However, if you want or need to install from source, then you download from here.

$ bsdtar -xf binutils-2.33.1.tar.bz2
$ mkdir binutils-build
$ cd binutils-build

Before you compile you must decide where want to install it:

  • To /usr
  • To some other directory, /opt for example

If you decide to install in /usr and you want the compiler to co-live with your source-to-source compiler (the non-cross compiler) then you must do a few things different.

and compile with the following commands:

$ ../binutils-2.33.1/configure --prefix=/usr \
                               --enable-ld=default \
                               --enable-gold \
                               --enable-plugins \
                               --enable-threads \
                               --with-pic \
                               --enable-shared \
                               --disable-werror \
                               --build=$(./config_guess) \
                               --target=avr
$ make configure-host
$ make tooldir=/usr

Now there are two options to install:

The last version we tested was GCC 7.3.0, which you can download here.

Then, unpack it in a directory:

$ bsdtar -xf gcc-7.3.0.tar.xz

Then, create a build directory and configure GCC in it:

$ mkdir build
$ cd build
$ ../gcc-7.3.0/configure --disable-libssp \
                         --disable-libstdcxx-pch \
                         --disable-libunwind-exceptions \
                         --disable-linker-build-id \
                         --disable-nls \
                         --disable-werror \
                         --disable-__cxa_atexit \
                         --enable-checking=release \
                         --enable-clocale=gnu
                         --enable-gnu-unique-object \
                         --enable-gold \
                         --enable-languages=c,c++ \
                         --enable-ld=default \
                         --enable-lto \
                         --enable-plugin \
                         --enable-shared \
                         --infodir=/opt/gcc/info \
                         --libdir=/opt/gcc/lib \
                         --libexecdir=/opt/gcc/lib \
                         --mandir=/opt/gcc/share/man \
                         --prefix=/opt/gcc \
                         --target=avr \
                         --with-as=

To be continued…