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
Compile with warnings, debug with symbols, and use sanitizers to catch bugs early.
For local work, start with strong warnings.
-std=c++23 -Wall -Wextra -Wpedantic
These warnings catch suspicious code early. Treat a new warning as a bug report until you can justify ignoring it.
Add debug symbols and disable heavy optimization while diagnosing problems.
-g -O0
Use low optimization while diagnosing logic bugs so stepping and variable inspection stay trustworthy.
-fsanitize=address,undefined
These catch memory and undefined-behavior bugs that might otherwise look random.
For concurrent code, create a separate ThreadSanitizer build instead of trying to combine every sanitizer in one binary.
g++ -std=c++23 -Wall -Wextra -Wpedantic -g -fsanitize=address,undefined src/main.cpp -o build/app
./build/app
This is enough for small projects before you introduce CMake or a larger build layout.
When you can reproduce a bug with one small test, debugging becomes faster and future regressions become cheaper to catch.
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.
Run them in dedicated builds instead of combining every tool in one configuration.
Debug: fast rebuilds, symbols, no heavy optimization.AsanUbsan: memory and UB checks for local diagnosis.Release: optimized build for performance checks.Even if you do not use CMake presets literally, thinking in named configurations keeps workflow decisions consistent.
When you find a bug, record the failing input, compiler, build flags, and exact observed output. That information turns debugging from guessing into engineering.
g++ -std=c++23 -Wall -Wextra -Wpedantic -g src/main.cpp -o build/app-debug
Add a second build configuration with sanitizers enabled. Use it for debugging sessions and keep a faster release build for routine runs.
g++ -std=c++23 -Wall -Wextra -Wpedantic -g -fsanitize=address,undefined src/main.cpp -o build/app-asan