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 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 /srcCommon 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.
apt-get install -y zlib1g-dev
rm -rf build
cmake -S . -B buildTell CMake where the file is
If the dependency is in a custom prefix, set the variable or the prefix path explicitly.
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/includeHow to prevent it
- Delete the build directory when changing dependencies, not just re-run cmake.
- Install all
-devpackages the project’s find_* calls require. - Guard optional dependencies with
if(NOT X_FOUND)so a missing one fails clearly.