cmake build_error ai_generated true

CMake Error: Could NOT find OpenCV (missing: OpenCV_DIR)

ID: cmake/find-package-not-found

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3 active

Root Cause

find_package() cannot locate a dependency. Config file or Find module not in search path.

generic

Workarounds

  1. 92% success Install development package via system package manager
    sudo apt install libopencv-dev
  2. 88% success Set package-specific _DIR variable
    cmake -DOpenCV_DIR=/path/to/opencv/build ..
  3. 85% success Use CMAKE_PREFIX_PATH for custom installs
    cmake -DCMAKE_PREFIX_PATH=/opt/opencv ..

Dead Ends

Common approaches that don't work:

  1. Set CMAKE_PREFIX_PATH to the source directory 78% fail

    Should point to INSTALL prefix (where lib/cmake/ lives), not the source tree

  2. Copy .cmake files into your project 80% fail

    Bundling third-party cmake configs creates version mismatches

  3. Use find_library() as drop-in replacement 72% fail

    find_library() only finds .so/.a but not headers, definitions, or transitive deps