C++ · Beginner level

Beginner level · Module 1: C++ Toolchain and First Programs · Lesson 2 of 3

Setting Up the Compiler and Editor

Install a compiler and an editor, build with warnings enabled and run programs from the terminal and the editor.

In this lesson you will

  • Install g++ (or Clang/MSVC) and configure an editor
  • Use compiler flags for warnings and the C++ standard

Key concepts

g++ / clang++ / MSVC-Wall -Wextra-std=c++20terminal workflow

The lesson

Free, standards-compliant compilers exist for every platform: GCC (g++) on Linux and Windows through MinGW-w64, Clang on macOS and Linux, and Microsoft's compiler with Visual Studio Community on Windows. Check the installation with g++ --version.

Always build with warnings: -Wall -Wextra make the compiler point out suspicious code such as unused variables or comparisons between signed and unsigned values. Treat every warning as a bug to fix. -std=c++20 selects the language version used in this course.

An editor such as VS Code with a C++ extension adds highlighting, completion and a debugger. Learn the terminal build command too; it is what build tools and servers run, and it works when an editor does not.

Step by step

  1. Install a compiler and check its version.
  2. Install an editor with C++ support.
  3. Build a program with -Wall -Wextra -std=c++20.
  4. Introduce an unused variable and read the warning.

Practice activity

Set up the toolchain, then write a program that prints your name and course and compiles with no warnings.

Expected result: The program builds from the terminal with all warning flags and produces no warnings.

Check your understanding

  1. What does -Wall -Wextra do?

    Show answer

    Turns on many compiler warnings about suspicious code.

  2. Why learn the terminal build command if the editor has a Run button?

    Show answer

    It is what build tools and servers use and it works without the editor.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.