cmake
build_error
ai_generated
true
CMake Error: Could NOT find OpenCV (missing: OpenCV_DIR)
ID: cmake/find-package-not-found
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3 | active | — | — | — |
Root Cause
find_package() cannot locate a dependency. Config file or Find module not in search path.
genericWorkarounds
-
92% success Install development package via system package manager
sudo apt install libopencv-dev
-
88% success Set package-specific _DIR variable
cmake -DOpenCV_DIR=/path/to/opencv/build ..
-
85% success Use CMAKE_PREFIX_PATH for custom installs
cmake -DCMAKE_PREFIX_PATH=/opt/opencv ..
Dead Ends
Common approaches that don't work:
-
Set CMAKE_PREFIX_PATH to the source directory
78% fail
Should point to INSTALL prefix (where lib/cmake/ lives), not the source tree
-
Copy .cmake files into your project
80% fail
Bundling third-party cmake configs creates version mismatches
-
Use find_library() as drop-in replacement
72% fail
find_library() only finds .so/.a but not headers, definitions, or transitive deps