Compiling opencv samples: unknown cmake command ocv_check_dependencies

岁酱吖の 提交于 2019-11-28 09:56:38
Zzirconium

Actually for OpenCV 2.4.4 beta the root CMakeList.txt file says:

OCV_OPTION(BUILD_EXAMPLES "Build all examples"

-DBUILD_EXAMPLES=ON worked just fine for me.

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

Xin Wang

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

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

g++ facedetect.cpp -o facedetect `pkg-config --libs opencv`

The macro 'ocv_check_dependencies' is defined in: your_path_to/opencv/cmake/OpenCVModule.cmake

# ensures that all passed modules are available
# sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE
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 top level CMakeLists.txt contains 'include' commands for files from opencv/cmake/ . Which is why the macro is available when you compile by calling cmake from the root of the opencv sources.

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

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.

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!