Compiling opencv samples: unknown cmake command ocv_check_dependencies

后端 未结 8 1074
余生分开走
余生分开走 2020-12-06 02:05

I am trying to build the OpenCV samples which come with the source package and I get the following:

CMake Error at CMakeLists.txt:10 (ocv_check_dependencies)         


        
相关标签:
8条回答
  • 2020-12-06 02:11

    I got similar errors. My approach is as following: 1) cd xxx/samples 2) mkdir build 3) cd build 4) cmake .. 5) make Now it works. We could not build individual project under their source files.

    0 讨论(0)
  • 2020-12-06 02:17

    Reason

    error message context:

    CMake Error at CMakeLists.txt:10 (ocv_check_dependencies):
      Unknown CMake command "ocv_check_dependencies".
    

    This error message happens because cmake can't find the definition of ocv_check_dependencies

    That's why the console said Unknown CMake command

    Solution

    If cmake cannot find where ocv_check_dependencies is defined

    Just like @Nick Hockings Said:

    ocv_check_dependencies is a macro defined in Your/OpenCV/path/OpenCVModule.cmake

    macro(ocv_check_dependencies)
      set(OCV_DEPENDENCIES_FOUND TRUE)
      foreach(d ${ARGN})
        if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
          set(OCV_DEPENDENCIES_FOUND FALSE)
          break()
        endif()
      endforeach()
    endmacro()
    

    The fastest way is to copy this snippet above to your CMakeList.txt file right above where ocv_check_dependencies is

    Therefore, cmake can finally understand what it is

    That should do the trick, i hope no one else will bother with this question in the future

    0 讨论(0)
  • 2020-12-06 02:23

    Following steps works for me.

    Export toolchain path.

    cd opencv-3.3.0/samples

    cross_cmake && cross_make

    cd opencv-3.3.0/samples/cpp/

    0 讨论(0)
  • 2020-12-06 02:28

    How to compile OpenCV sample code ?

    # For OpenCV 3 
    cd /path/to/opencv/samples/cpp/
    #Compile
    g++ -ggdb `pkg-config --cflags --libs opencv` facedetect.cpp -o facedetect
    #run
    ./facedetect
    

    Works for me.

    googled from this link

    0 讨论(0)
  • 2020-12-06 02:29

    I got it.

    In order to build the samples one has to change the default configuration for cmake by providing it via -D. What I did wrong was that I tried to execute cmake from within the samples directory.

    The proper way to build the samples is invoking cmake like so (from within the root directory of the unpacked archive):

    cmake -DBUILD_SAMPLES .
    

    which will turn samples ON. One can proceed using make, make install than. The samples can be found in bin after building.

    See also FAQ

    0 讨论(0)
  • 2020-12-06 02:29

    mydragonisland's build instructions almost worked for me; with a minor reordering and including accents:

    g++ facedetect.cpp -o facedetect `pkg-config --libs opencv`
    
    0 讨论(0)
提交回复
热议问题