In this article, I will explain how I am setting up my new Ubuntu desktop system for C/C++ development. In particular, I am going to install build-systems (Make, CMake and Ninja), compilers (GCC, Clang and Arm-GCC) and some supporting tools (e.g. Doxygen).
Prerequisites
- A system with Ubuntu installed. In particular, I am using Ubuntu 22.04 LTS.
- Some knowledge of the usage of the Terminal is required.
- (Optional) A good terminal setup. I described my setup in the previous article.
I learned most parts of this setup process in the course Creating a Cross-Platform Build System for Embedded Projects with CMake from Embedded Artistry. The course goes more in-depth on the installation process of other tools, and it covers all the major OSes. If you need to learn more about CMake, go for it.
Build Systems Installation
CMake is the main tool I would like to use to create the build system. It can be installed either with apt
or pip
. The version installed using the first method is not updated frequently, so I decided to proceed using Python.
After running this last command, a warning is returned: CMake is installed in ~/.local/bin/
, which is not on PATH. To run the command, I need to add the directory to the PATH variable.
If you are using Terminal setup (Zsh and Oh-My-Zsh), you need to do the following.
- Open
~/.zshrc
- Near the start of the file search the comment which is mentioning PATH and add the following lines
path+=('/home/<user>/.local/bin')
where<user>
must be replaced by your userexport PATH
- Close and reopen Terminal
Instead, if you are using the default Bash shell, you need to add the following into ~/.bashrc
Now I can check the CMake version.
Finally, I can install Ninja.
Make is missing because it will be installed later.
Toolchains Installation
Now I need to install the toolchains, i.e. the compilers used to translate C into machine code.
First, let’s install the build-essential
package which contains (among other things):
- Make
- The GCC compiler
- The
libc
library
I will also install the Clang compiler.
It’s time for embedded toolchains. I would like to install the ARM GNU Toolchain. Unfortunately, this process is a little bit more complicated because ARM does not provide the toolchain on package managers.
- Go to the Arm GNU Toolchain website
- Click on the Download ARM GNU Toolchain button
- Download the tarball appropriate for the system (in this case x86_64 Linux
.tar.xz
) - Install the compression software XZ Utils using
sudo apt install xz-utils
- Unpackage the tarball with
tar -vxf <filename>.tar.xz
- Place the directory somewhere on your system
- In my case, I decided to place it in
~/.local/toolchains
- In my case, I decided to place it in
Now, I need to add the bin
directory to PATH.
You can follow the same instructions of the previous paragraph. Based on your shell, you will have something like:
Finally, I can re-open the Terminal and check if the ARM Toolchain is detected by checking its version.
Supporting Tools Installation
The core tools are now ready, but I would like to install other software generally helpful when dealing with C/C++ code.
I will explore the usage of these tools in later posts.
Text Editor Setup
Finally, I need a text editor. Everyone has their own favourite, and I am not here to discuss which one is the best. Personally, I find Visual Studio Code pleasant, so I installed this one.
In case you are using it too, you can find it useful to install the following extensions:
Conclusion
If you followed this article, you should have all the tools necessary to write and build C/C++ code, including support for cross-compilation.
In the following posts, we will use them extensively.