# CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2)

**Code:** `Could not find a package configuration file` · **Category:** C/C++ · **Seen on:** C/C++, CMake, Linux

`find_package(Foo)` could not locate the library's CMake config (FooConfig.cmake or FindFoo.cmake), so the library is not installed or CMake is not told where it is.

## Meaning

CMake searches standard prefixes plus `CMAKE_PREFIX_PATH`, `<Package>_DIR` and the system package registry. Install the library's development package, or point CMake at the install prefix. For libraries that provide only pkg-config files, use `find_package(PkgConfig)`.

## Common causes

- Development package not installed (`libfoo-dev`, `foo-devel`, Homebrew formula)
- Library installed in a custom prefix CMake does not search
- Wrong package name or case (`OpenCV` vs `opencv`)
- Version requested is higher than the installed one
- Package ships only a pkg-config file, no CMake config

## Quick fix

1. Install the development package or build the library and `cmake --install` it
2. Pass the prefix: `cmake -DCMAKE_PREFIX_PATH=/opt/foo ..` or `-DFoo_DIR=/opt/foo/lib/cmake/Foo`
3. Check the exact package name in the library docs

## Detailed fix by platform

### CMake

1. `cmake -S . -B build -DCMAKE_PREFIX_PATH=/opt/foo`
2. Debug the search: `cmake --debug-find -S . -B build` (3.17+)
3. For pkg-config libraries: `find_package(PkgConfig REQUIRED)` + `pkg_check_modules(FOO REQUIRED foo)`

### Linux

1. `apt search libfoo-dev` / `dnf search foo-devel` to find the package; `find / -name "FooConfig.cmake" 2>/dev/null` to locate an existing install

## Code examples

### Telling CMake where the package is

```cmake
cmake_minimum_required(VERSION 3.16)
project(app)

find_package(Foo 1.2 REQUIRED)               # looks for FooConfig.cmake
add_executable(app main.cpp)
target_link_libraries(app PRIVATE Foo::Foo)

# configure with:
#   cmake -S . -B build -DCMAKE_PREFIX_PATH=/opt/foo
```

## How to diagnose

1. **Name** — Exact package name in the docs?
2. **Install** — Is FooConfig.cmake on disk?
3. **Prefix** — Is its prefix in CMAKE_PREFIX_PATH?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/cmake-could-not-find-package)
