Build, Debug, and Test

Build, Debug, and Test

Compile with warnings, debug with symbols, and use sanitizers to catch bugs early.

Build, Debug, and Test

Compiler flags

For local work, start with strong warnings.

-std=c++23 -Wall -Wextra -Wpedantic

Debugging

Add debug symbols and disable heavy optimization while diagnosing problems.

-g -O0

Sanitizers

-fsanitize=address,undefined

These catch memory and undefined-behavior bugs that might otherwise look random.

Testing advice

A practical CMake loop

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build build
ctest --test-dir build --output-on-failure

This is the default workflow many modern C++ projects settle on, even when the codebase grows.

Sanitizer strategy

Run them in dedicated builds instead of combining every tool in one configuration.

Better bug reports

When you find a bug, record the failing input, compiler, build flags, and exact observed output. That information turns debugging from guessing into engineering.