Installation and setup

Pieter P

Table of Contents list

Operating Systems

This guide is focussed on Linux as an operating system. While it should be possible to do most of it on Windows as well, I wouldn't recommend it at all. Development tools are harder to install on Windows, and building the Docker containers will take much longer, especially if you don't have Windows Pro or Enterprise (Windows Home doesn't have Hyper-V and Containers support).
I've worked in a team where some developers preferred Windows, and I (eventually) got most of it to run correctly, but it wasn't worth it. Compiling large projects in a virtualized Docker container was many times slower than doing the same thing natively on Linux, the network configuration to connect to the Raspberry Pi directly was a pain, on-target debugging was not supported, because the Windows tools don't support gdb-server, etc.
In the end, everyone moved to Linux, because it was so much faster and easier to use.
If you want to get serious about developing C/C++ software for the Raspberry Pi, installing Linux is definitely worth it.

I'll be using Ubuntu 19.10 throughout this guide, but pretty much everything applies to other Linux distributions as well. The most significant difference will be the package manager used. On Ubuntu, I'll use APT and Snap, but most packages should be available in your distro's package manager as well.

Git

The RPi-Cpp-Toolchain repository uses Git as a version control system. Install it so you can download the repository in the next step.

Installation

Either download Git from the website, or install it using your package manager:

sudo apt install git

The RPi-Cpp-Toolchain repository

Clone the repository from GitHub. We'll clone it to ~/GitHub/RPi-Cpp-Toolchain, but feel free to put it wherever you like.

mkdir -p ~/GitHub
cd ~/GitHub
git clone https://github.com/tttapa/RPi-Cpp-Toolchain.git

Docker

I don't like to do a lot of installations on my main Linux box, so I built the toolchain and most of the libraries inside of a Docker container. This has the added benefit that all builds are reproducible, and it's easy to undo the previous step or even start from scratch.
You can find more information about the use of Docker on the next page.

Installation

You need Docker to pull or build the toolchain. Docker Compose is optional.
You can find detailed installation instructions here:

Visual Studio Code

This guide uses Visual Studio Code as the main editor, and the repository contains the necessary configuration files, build tasks, debug configurations, etc. If you know what you're doing, you can of course use any editor or IDE, with your own configuration files, but if you're a beginner, I'd recommend VSCode to follow along.

Installation

You can either download VSCode from https://code.visualstudio.com/, or if you're on Linux, you can install it as a Snap:

sudo snap install code --classic

Extensions

The two most important extensions we'll use in this project, are the C/C++ extension and the CMake Tools extension.
I'd also recommend installing CMake language support for syntax highlighting and suggestions in CMake code. If you plan on editing the Dockerfiles to modify the toolchain or the libraries, you might find the Docker extension useful as well.

Visual Studio Code with the recommended extensions installed.
Visual Studio Code with the recommended extensions installed.

Build tools

CMake

CMake is a tool to configure C/C++ projects. It takes care of dependencies between parts of your project, external libraries, and generates build files that are later used to compile the code.

You can download the latest version of CMake from the official website, or you can install it using your package manager:

sudo apt install cmake

Make

After the project is configured using CMake, Make is used to build everything. It tracks dependencies and invokes the compiler and other tools to compile all code with the options determined by CMake.

You can download the source code for Make from the website, but it's much easier to just install it using the package manager:

sudo apt install make

If you've installed CMake using the package manager, Make will probably already be installed.

GCC (optional)

GCC is a collection of compilers, including C, C++ and Fortran compilers. We'll build our own GCC cross-compilation toolchain later, so you don't really need to install a native version of GCC on your computer, but I'd recommend it nonetheless. It's very useful for testing and debugging parts of your code that don't have to be run on the Raspberry Pi.

You can install your distro's default version of GCC using the package manager:

sudo apt install gcc g++

However, the default version is often out of date, especially on LTS releases of Ubuntu. Luckily, you can easily install the latest version from the ubuntu-toolchain-r/test PPA:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt install gcc-9 g++-9