14

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):
  Unknown CMake command "ocv_check_dependencies".

I did install OpenCV using

cmake .
make
sudo make install

and I got a tutorial snippet working (thus I suppose it is installed correctly as a library). However, compiling the samples does not work.

I guess I have to somehow configure CMake to have “ocv_check_dependencies” - but how? I am lost!

1
  • have you tried an out-of-source build? Commented Oct 30, 2012 at 21:39

8 Answers 8

22

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer. -DBUILD_EXAMPLES=ON is used across all documentation. See for example the linux tutorial.
18

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

4 Comments

Thanks for this! I spot a couple of typos, though. A missed space and examples rather than samples. Do you mean cmake -D BUILD_EXAMPLES .?
On my machine it did not work with a space. They speak of samples and it really is "BUILD_SAMPLES". According to the documentation it is -D BUILD_SAMPLES=ON, however the above worked for me.
I tried BUILD_SAMPLES and it wouldn't work, so I looked in the CMakeLists file and saw BUILD_EXAMPLES. I was using the Unix source, maybe you're using another one? Anyway, these comments will be here for anybody else who has this problem
It seems like you 're running cmake in a source directory. Not recommended AFAIK
3

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

1 Comment

@drewish Thank you for your advice.
1

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

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

Comments

1

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.

2 Comments

If my answer helped you please give it an up vote, so that other users know. Thanks, Nick
Sure, it's my pleasure
1

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

Comments

0

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.

Comments

0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.