SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
C++ New Added 10 September 2026

CMake Error: Could not find a package configuration file provided by X

find_package looked for a config file the library installs, XConfig.cmake or x-config.cmake, and no directory it searched had one. The library being present in the system is not enough: the runtime package often ships without the config file, which lives in the development package or in a prefix CMake was never told about.

Quick fix

Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.

Quick fix
# The error lists every path it tried: read that list first
cmake -S . -B build 2>&1 | sed -n '/Could not find a package/,/^$/p'

# The config file usually comes with the -dev or -devel package
sudo apt install libfmt-dev          # Debian, Ubuntu
brew install fmt                     # macOS

# Where did it land
find /usr /opt/homebrew -name 'fmtConfig.cmake' 2>/dev/null

# Point CMake at a prefix, or straight at the directory
cmake -S . -B build -DCMAKE_PREFIX_PATH="/opt/homebrew;/usr/local"
cmake -S . -B build -Dfmt_DIR=/opt/homebrew/lib/cmake/fmt

# vcpkg and Conan need their toolchain file
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake

# Case matters: find_package(FMT) will not find fmtConfig.cmake

How to diagnose C++ errors

C++ errors fall into two very different worlds. Compile and link errors (undefined reference, multiple definition, template substitution failure) are deterministic and are almost always about declarations, the One Definition Rule, or link order. Runtime memory errors (segfaults, double free, use-after-free) are non-deterministic and should never be debugged by reading code alone; a sanitizer will find in seconds what code review misses for days.

If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.

  1. Rebuild with sanitizers before anything else: -fsanitize=address,undefined -fno-omit-frame-pointer -g. AddressSanitizer reports the exact allocation and free sites for use-after-free and double-free.
  2. For undefined-reference errors, check link order, remembering that with GNU ld libraries must come after the objects that use them, and check for a C/C++ linkage mismatch that needs extern "C".
  3. Use nm -C libfoo.a | grep symbol to confirm the symbol is actually present and to see the demangled signature. A signature that differs by a const is a different symbol.
  4. Enable core dumps (ulimit -c unlimited) and open them in gdb with gdb ./binary core, then bt full. A stack trace beats speculation.
  5. For template errors, read the message from the bottom up. The final line is usually the real constraint that failed; everything above is instantiation context.

Tools worth reaching for

  • -fsanitize=address,undefined
  • valgrind
  • gdb / lldb
  • nm -C
  • ldd

Authoritative references

Primary documentation for this error, worth reading before applying any fix in production.

cmake.org

Related C++ errors

See all 11 C++ errors →

Browse other categories

Something missing or wrong?

This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.