Skip to content
Topos Uranos

Installing the environment on Windows, macOS and Linux

Summary

This lesson sets up and checks the environment that will be used throughout the course. It first explains what is installed and why: a compiler, which is a separate program; an editor, Visual Studio Code, which invokes it; its official C++ extension; and the terminal, from which the compiler is invoked without intermediaries. It then offers a complete guide for each system: on Windows, MSYS2 with the UCRT64 environment and GCC, or Microsoft’s compiler as an alternative; on macOS, the Command Line Tools for Xcode with Clang, or GCC from Homebrew if Apple’s version is not enough; on Linux, the distribution’s GCC on Debian and Ubuntu, Fedora and Arch. Next comes the installation of the editor and of its extension, identical on the three systems, and the configuration of the Windows console so that it writes and reads text in UTF-8. It ends with a test program, which writes a line with accented letters and the C++ standard the compiler applies, and with the frequent failures of the installation, each with its cause and its remedy.

Learning objectives

  1. Install on one’s own system a compiler with C++23 support and check its version from the terminal.
  2. Install Visual Studio Code and its official C++ extension, and open a working folder with it.
  3. Compile and run the first test program, from the terminal and from the editor.
  4. Diagnose and solve at least three frequent installation failures (compiler not found, old version, standard not recognized).

What is installed and why

In the lesson Programs, compilers and C++ we saw that a program written in C++ is not run as it is written: a compiler translates it into an executable, a file with machine instructions that the operating system can start. If this is so, programming requires at least two different things: a place in which to write the text of the program and a translator that turns it into an executable. The first is provided by an editor; the second, by the compiler. They are separate programs, which are installed separately and can fail separately, and they should not be confused: the editor compiles nothing; it asks the compiler to compile and shows what the compiler answers.

This separation has a practical consequence on which all the guides of this lesson depend. When the editor “compiles”, it actually writes in a terminal a command such as g++ main.cpp -o main, just as the student could write it. It follows that everything the editor does can also be done by hand in the terminal, the text window in which commands for the operating system are written; and that, if the editor fails, the terminal makes it possible to find out whether the defect lies in the editor or in the compiler. That is why the course works with both from the first day: the editor for convenience, the terminal to know what is happening.

Four pieces are installed.

  • The compiler, with its standard library. The course uses the C++23 standard, so the compiler must recognize it and its library must include the header <print>, which provides std::println. GCC (whose command for C++ is g++) will be used on Windows and on Linux, and Clang (clang++) on macOS. GCC 15 or later is required: the header <print> reached GCC’s library with version 14, but printing a whole collection with std::println, which the course does from the lesson Programs, compilers and C++ on and in many later lessons, arrived only with version 15. On macOS, the tools of Xcode 16 or later.
  • The editor: Visual Studio Code, free and the same program on the three systems, so that the course’s instructions apply to all of them.
  • Microsoft’s official C/C++ extension for Visual Studio Code, which teaches the editor the language: it colors the code, flags errors as one types, completes names and knows how to invoke the compiler and the debugger.
  • The debugger, GDB on Windows and Linux, LLDB on macOS: a program that makes it possible to stop the execution of a program and look at its state. It is installed now together with the compiler and will be used from unit 4 on.

The following guides are independent: each student follows the one for their own system and then skips to the section on Visual Studio Code. In the command blocks, the sign $ at the start of a line represents the terminal prompt and is not typed; the lines without it are what the terminal answers. The official sites cited are the only ones from which it is advisable to download: an installer obtained elsewhere may be outdated or tampered with.