If you installed RT Linux, you downloaded the project tools from the RaspberryPi project.

This toolchain is very old (gcc version 4) so you cannot use the new features of C++, and raspberry pi does not provide an up to date toolchain.

That is why we are going to build a new toolchain.

We are going to use a tool named crosstool-ng.

If you have any trouble during the process, you can go to the official documentation to find help.

Before starting the install

Before starting the install you need to install all the packages needed for the toolchain.

Depending on your system you can find needed packages on the page os-setup from the official doc of Crosstools-NG. As explained on this page, if you are on Linux, you have to reach the folder crosstool-ng/testing/docker/ from the GitHub project Crosstool-NG. Then, choose the folder corresponding to your distribution. For example, if your os is Ubuntu 18.04, open the folder and the Dockerfile.

FROM ubuntu:18.04
ARG CTNG_UID
ARG CTNG_GID
RUN groupadd -g $CTNG_GID ctng
RUN useradd -d /home/ctng -m -g $CTNG_GID -u $CTNG_UID -s /bin/bash ctng
RUN apt-get update
RUN apt-get install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev \
    python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip \
    patch libstdc++6
RUN wget -O /sbin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64
RUN chmod a+x /sbin/dumb-init
RUN echo 'export PATH=/opt/ctng/bin:$PATH' >> /etc/profile
ENTRYPOINT [ "/sbin/dumb-init", "--" ]

You can use the contents of this file as a list of the packages that need to be installed on Ubuntu 18.04. In this case, you only need to enter this command:

sudo apt update
sudo apt upgrade
sudo apt install -y gcc g++ gperf bison flex texinfo help2man make libncurses5-dev python3-dev autoconf automake libtool libtool-bin gawk wget bzip2 xz-utils unzip patch libstdc++6

After this install you can proceed to the build process.

Building the toolchain

You can find a script toolchain.sh to automatically build the toolchain in you home.

This script is just an easy way to set up and build your toolchain.

If you want a more sophisticated one you are encouraged to modify the script or go to the official documentation for more infos.

The script

First a menu will ask you at which step you want to go.

This is in case something failed and you want to restart the build without changing the configuration.

If this is the first time running the script, type 1 to do all the steps.

Launch the script

This script will download and build crosstool-ng in a subfolder created at the script’s location.

Then it will set up the configuration for the RaspberryPi 3 and open you a menu to configure the toolchain. Config menu

You can change everything you want for your toolchain.

It will then build the toolchain.

This step takes a lot of time(For raspberry it takes almost 35 minutes depending on your computer).

Install the toolchain

By default the toolchain is installed in the directory ~/x-tools/

To be able to easily use it you need to add it to your PATH variable:

  • If you want to add it temporarily in your terminal just enter:
    export PATH="${PATH}:${HOME}/x-tools/armv8-rpi3-linux-gnueabihf/bin"
    
  • If you want is permanently added to your PATH, add it at the end of your ~/.bashrc:
    echo "export PATH=\"\${PATH}:${HOME}/x-tools/armv8-rpi3-linux-gnueabihf/bin\"" >> ~/.bashrc