Skip to content
Latchkey

CMake "The following variables are used ... but set to NOTFOUND"

CMake configured far enough to need a path or library it never resolved. The cache variable holds the sentinel NOTFOUND, so generation stops and lists every unresolved variable.

What this error means

Configure fails listing one or more variables "set to NOTFOUND", usually a *_LIBRARY or *_INCLUDE_DIR. It typically follows a find_library()/find_path() that did not locate the dependency.

CMake output
CMake Error: The following variables are used in this project, but they are
set to NOTFOUND. Please set them or make sure they are set and tested
correctly in the CMake files:
ZLIB_LIBRARY (ADVANCED)
    linked by target "app" in directory /src

Common causes

A library or header was never found

A find_library()/find_path() returned NOTFOUND because the -dev package is missing or the file lives outside the search paths, and the result is used unconditionally.

Stale NOTFOUND cached from a prior failed configure

Once a variable is cached as NOTFOUND, CMake will not re-search it on the next run. Installing the dependency without clearing the cache leaves the stale value in place.

How to fix it

Install the missing library, then re-configure clean

Add the dependency and wipe the cache so CMake re-runs its find steps.

Terminal
apt-get install -y zlib1g-dev
rm -rf build
cmake -S . -B build

Tell CMake where the file is

If the dependency is in a custom prefix, set the variable or the prefix path explicitly.

Terminal
cmake -S . -B build -DCMAKE_PREFIX_PATH=/opt/zlib
# or set the specific cache variable
cmake -S . -B build -DZLIB_LIBRARY=/opt/zlib/lib/libz.so -DZLIB_INCLUDE_DIR=/opt/zlib/include

How to prevent it

  • Delete the build directory when changing dependencies, not just re-run cmake.
  • Install all -dev packages the project’s find_* calls require.
  • Guard optional dependencies with if(NOT X_FOUND) so a missing one fails clearly.

Frequently asked questions

What causes ""set to NOTFOUND""?
A find_library()/find_path() returned NOTFOUND because the -dev package is missing or the file lives outside the search paths, and the result is used unconditionally.
How do I fix "set to NOTFOUND"?
Add the dependency and wipe the cache so CMake re-runs its find steps.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card