Modern C++ • C++20 baseline
Set Up a Compiler and Build a C++ Program
Compile a source file with an explicit language standard and useful warnings.
Install a compiler such as GCC, Clang, or MSVC and save source in a .cpp file. A build command should make the language version and diagnostics visible instead of relying on whichever defaults happen to be installed. Larger projects should record the same choices in a build system so every developer and CI job uses them.
Key points
- C++20 is requested with -std=c++20 on GCC and Clang.
- Warnings help find mistakes but do not replace tests or code review.
Example
g++ -std=c++20 -Wall -Wextra -Wpedantic main.cpp -o app
./app
What to expect
The first command compiles main.cpp; the second runs the app executable.
Practice exercise
Compile the first program from the terminal, then deliberately introduce an unused variable and inspect the warning.
Key idea: Keep compiler version, standard mode, warnings, and build steps reproducible.