Ninja "ninja: error" in CMake Builds
Ninja could not run the build graph. The build.ninja is missing, stale, or references an input that no longer exists - usually after switching CMake generators or reusing a dirty build directory.
What this error means
The build fails with a ninja: error - commonly "loading 'build.ninja': No such file or directory" or "'<file>', needed by '<target>', missing and no known rule to make it".
ninja: error: '/src/generated/version.cpp', needed by 'CMakeFiles/app.dir/version.cpp.o', missing and no known rule to make itCommon causes
No build.ninja (CMake not configured with Ninja)
Calling ninja before cmake -G Ninja configured the directory means there is no build.ninja to load.
Stale build dir or missing generated input
A cached build directory from a different generator or commit references inputs that no longer exist, so Ninja cannot satisfy the graph.
How to fix it
Configure with the Ninja generator first
cmake -S . -B build -G Ninja
ninja -C buildWipe a stale build directory
When the graph references files that no longer exist, regenerate from a clean configure.
rm -rf build
cmake -S . -B build -G Ninja
ninja -C buildHow to prevent it
- Always
cmake -G Ninjabefore invokingninja. - Do not cache the CMake build directory across generator or major-version changes.
- Key any build-dir cache on the CMake version and generator.