AI Skill Report Card

Debugging C++ CMake Projects

B74·Nov 29, 2026·Source: Extension-page

Debugging C++ / CMake Projects

12 / 15

When given a C++ project plus compiler output, do this first:

Bash
# 1. Reproduce with warnings maxed out g++ -std=c++17 -Wall -Wextra -Wpedantic Main.cpp -o app # 2. Configure each CMake target independently cmake -S . -B build-tui cmake -S JNA-Desktop -B build-desktop cmake -S JNA-Mobile -B build-mobile -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake

Fix what the compiler actually reports before guessing at anything else.

Recommendation▾
Replace the abstract Examples section with real before/after pairs: paste an actual compiler log or CMake error, then show the exact patch and the clean rebuild output. Examples 2 and 3 currently describe outcomes in prose rather than showing input and output, and none show a bad result next to a good one.
12 / 15
Progress:
- [ ] Step 1: Clarify ambiguous requests only when a wrong guess is costly
- [ ] Step 2: Reproduce (compile/configure) and capture exact diagnostics
- [ ] Step 3: Triage into build errors, warnings, runtime bugs, layout problems
- [ ] Step 4: Fix smallest-first, one category at a time
- [ ] Step 5: Verify each target separately; state honestly what was NOT verified
- [ ] Step 6: Report what changed and what still needs the user's environment

Step 1: Resolve ambiguity quickly

Pick the most probable meaning and state the assumption, rather than stalling.

  • "MS White" / "MS Wight" most likely means MSVC (Microsoft's compiler) or MSYS2. Default to MSVC if the project targets Windows desktop; MSYS2/MinGW if the log shows g++/gcc.
  • If the user gets frustrated ("just do it"), stop asking questions and act on the best assumption.

Step 2: Reproduce

  • Build every target on its own. A root CMakeLists.txt that only builds Main.cpp does not cover Qt targets.
  • Keep the first error. Later errors are usually cascades.

Step 3: Triage

CategoryTypical signsFirst move
Build errorundefined reference, No such fileCheck target_link_libraries, include paths, find_package
Warning-Wignored-attributes etc.Fix the type, don't silence blindly
Runtime logicwrong output, lost dataTrace state changes and persistence
Layoutone CMake for three appsSplit per-target CMake files

Step 4: Fix patterns

Pattern A: -Wignored-attributes on unique_ptr<FILE, decltype(&pclose)> decltype(&PCLOSE) carries platform calling-convention attributes. Use a custom deleter type:

C++
struct PipeCloser { void operator()(FILE* f) const { if (f) PCLOSE(f); } }; std::unique_ptr<FILE, PipeCloser> pipe(POPEN(cmd, "r"));

Pattern B: Prefix-matching commands if (input.find("clear") == 0) also matches clearance. Require an exact match after trimming:

C++
auto trim = [](std::string s){ s.erase(0, s.find_first_not_of(" \t\r\n")); s.erase(s.find_last_not_of(" \t\r\n") + 1); return s; }; if (trim(input) == "clear") { /* ... */ }

Pattern C: State cleared but not persisted After any mutation (clear, delete, edit) call the save routine. Verify by reloading from disk.

Pattern D: Demo/sandbox mode overwriting real data In non-interactive environments (no TTY), detect with isatty(STDIN_FILENO) and skip writes to the user's saved files.

Pattern E: Splitting UTF-8 when truncating Never cut at a raw byte offset. Back up while (c & 0xC0) == 0x80:

C++
size_t cut = std::min(max, s.size()); while (cut > 0 && (static_cast<unsigned char>(s[cut]) & 0xC0) == 0x80) --cut; return s.substr(0, cut);

Pattern F: Terminal UI not appearing Flush after each frame: std::cout << frame << std::flush;. Without it, output is buffered and the screen looks frozen.

Pattern G: Qt CMake

CMAKE
cmake_minimum_required(VERSION 3.21) project(JNA-Desktop LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) find_package(Qt6 REQUIRED COMPONENTS Quick Qml) qt_add_executable(JNA-Desktop Main.cpp AppStore.cpp JHClient.cpp Terminal.cpp) qt_add_qml_module(JNA-Desktop URI JNA VERSION 1.0 QML_FILES Main.qml) target_link_libraries(JNA-Desktop PRIVATE Qt6::Quick Qt6::Qml)
  • Load QML via the module URI (qrc:/JNA/Main.qml), not a relative filesystem path.
  • Mobile adds Android properties (QT_ANDROID_PACKAGE_SOURCE_DIR pointing at android/).

Step 5: Verify honestly

If you cannot build Qt or Android in the current environment, say so. Never claim "tested" when only the plain C++ target was compiled.

Recommendation▾
Make the skill general instead of tailored to one project. File names (JNA-Desktop, AppStore.cpp, JHClient.cpp), the 'MS White' guess, and the frustrated-user scenario narrow its usefulness. Move project-specific details into a separate reference file, and add generic CMake failure modes such as missing find_package, wrong target_link_libraries visibility, generator mismatches, and out-of-source build issues.
13 / 20

Example 1: Online compiler warning Input: warning: ignoring attributes on template argument 'int (*)(FILE*)' at unique_ptr<FILE,decltype(&PCLOSE)> Output: Replace the decltype(&PCLOSE) deleter with a PipeCloser functor (Pattern A); recompile with -Wall -Wextra and confirm zero warnings.

Example 2: "Make a separate CMake for mobile" Input: Repo has root CMakeLists.txt, JNA-Desktop/, JNA-Mobile/. Output: Root builds only the Qt-free TUI (Main.cpp). JNA-Desktop/CMakeLists.txt and JNA-Mobile/CMakeLists.txt each declare their own project, Qt find_package, sources, and (mobile) Android manifest settings. Document the three configure commands in README.md.

Example 3: Frustrated user Input: "You keep saying you found 500 bugs, just fix it." Output: Skip preamble. List the exact files changed with one line each, run the available build, and clearly flag what could not be tested.

Recommendation▾
Tighten the description and Quick Start. The description's trigger list reads like pasted user phrases ('separate CMake for mobile'); rewrite it as scenario-based triggers. The Quick Start commands assume a specific directory layout and Android NDK setup, so give a layout-agnostic first step (configure, build, capture the first error) and put target-specific commands later.
  • Fix from compiler output, not intuition.
  • Keep per-target CMake files independent; share code via a static library only if duplication grows.
  • Pin cmake_minimum_required(VERSION 3.21) and CMAKE_CXX_STANDARD 17 to match the online compiler (GCC 13, C++17).
  • Guard platform code: #ifdef _WIN32 for _popen/_pclose, otherwise popen/pclose.
  • Use if(UNIX) target_link_libraries(... pthread) only where threads are used.
  • Keep the README's build section in sync with the actual CMake layout.
  • Summarize in plain language: what broke, what changed, what is unverified.
  • Claiming a Qt or Android build works without running it.
  • Reporting vague counts of bugs ("fixed many issues") instead of specific changes.
  • Using prefix matching or substring checks for exact commands.
  • Mutating saved data inside demo or sandbox runs.
  • Truncating strings by bytes when they contain UTF-8 box-drawing characters.
  • Relying on a single root CMakeLists.txt for desktop, mobile, and TUI at once.
  • Asking repeated clarifying questions after the user has already signaled impatience.
  • Forgetting std::flush for ANSI-redrawn terminal UIs.
0
Grade BAI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
12/15
Workflow
12/15
Examples
13/20
Completeness
13/20
Format
13/15
Conciseness
11/15