Skip to content

Build an accurate project from CMake (compile_commands.json)

A compile_commands.json (a compilation database) records the exact files, include paths, and macros your build uses. Importing it produces a far more accurate C/C++ project than configuring by hand — and it keeps the Strict (Clang) parser well fed.

1. Generate compile_commands.json from CMake

In your build directory, enable the compile-commands export and re-run CMake:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
# Windows: use the NMake Makefiles generator
cmake -G "NMake Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .

You'll get a compile_commands.json in the build directory.

Not using CMake?

Tools like Bear generate the same compile_commands.json for other build systems, so this flow isn't CMake-only. Cross-compiled toolchains that can't emit one are covered in embedded / firmware projects.

2. Import it

In the New Project wizard: on the CMake Compilation page (“Specify CMake Compilation Database?”) point Understand at your compile_commands.json. (If one is already in the source directory you chose, the wizard offers to import it.)

From the CLI:

und -db project.und create -languages C++
und -db project.und add -cmake path/to/compile_commands.json
und -db project.und settings -C++AddFoundFilesToProject on
und -db project.und analyze

Each command is documented in the und reference: add, settings, analyze.

Staying in sync

Each time you compile, the build system rewrites compile_commands.json. In Understand, just Analyze — it rescans the JSON for changes and reanalyzes if needed; no reopening required. In a pipeline, run the same import and analyze steps after each build — see an end-to-end CI/CD pipeline.

If your project mixes C/C++ with other languages, each language has its own accuracy knobs — see the per-language accuracy notes.