C++
Module 35: Build Systems and Development ToolsAdvanced50 min read

CMake, Makefiles, GDB Debugging & AddressSanitizer (ASan/UBSan)

Automate builds with Make and modern CMakeLists.txt, debug with GDB/LLDB, and catch memory bugs using -fsanitize=address,undefined.

Key Takeaways & Core Concepts
  • generates native build files (Ninja, Make, Visual Studio) from CMakeLists.txt. Link static (.a) or shared (.so/.dll) targets cleanly with target_link_libraries.
  • Compile with -g for debug symbols; inspect backtraces (bt) and breakpoints in GDB/LLDB.
  • Enable AddressSanitizer & UBSan in CI/testing: g++ -g -O1 -fsanitize=address,undefined main.cpp to catch buffer overflows, use-after-free, and signed overflow immediately!

1. Make, CMake & Libraries

CMake generates native build files (Ninja, Make, Visual Studio) from CMakeLists.txt. Link static (.a) or shared (.so/.dll) targets cleanly with target_link_libraries.

1. Debug vs. Release Macro Verification
1#include <iostream>
2
3int main() {
4#ifdef NDEBUG
5 std::cout << "Release build (-O2/-O3)\n";
6#else
7 std::cout << "Debug build (-g, assertions active)\n";
8#endif
9 return 0;
10}
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
10 lines
Note: Release builds define `NDEBUG` to strip `assert()` checks.

2. Debugging (GDB/LLDB) & Sanitizers (ASan / UBSan / TSan)

  • Compile with -g for debug symbols; inspect backtraces (bt) and breakpoints in GDB/LLDB.
  • Enable AddressSanitizer & UBSan in CI/testing: g++ -g -O1 -fsanitize=address,undefined main.cpp to catch buffer overflows, use-after-free, and signed overflow immediately!
Practice & AssessmentC++ Programming Tutorial

Test Your Understanding

Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.

Your Current Score

0 / 0 correct(0 attempted)