How to build opencv samples

Viewed 710

I am new to cmake though not to make. This question is different from Could not build OpenCV Android sample project since that other question is about a single project and this one is looking at the overall CMakeLists.txt.

Speaking of which: consider the CMakeLists.txt in ${OPENCVDIR}/samples :

I followed basic process for cmake:

cd  "${OPENCVDIR}/samples"
mkdir build
cd build
cmake ..

But at the last step I have:

$ cmake ..
CMake Error at CMakeLists.txt:72 (find_package):
  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/git/opencv/samples/CMakeFiles/CMakeOutput.log".

Line 72 has this: find_package(OpenCV REQUIRED PATHS "..")

I looked at the error log and it was not informative.

Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is GNU, found in "/git/opencv/samples/CMakeFiles/3.13.4/CompilerIdCXX/a.out"

Determining if the C compiler works passed with the following output:
Change Dir: /git/opencv/samples/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_26f76/fast"
/usr/bin/make -f CMakeFiles/cmTC_26f76.dir/build.make CMakeFiles/cmTC_26f76.dir/build
make[1]: Entering directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o
/usr/bin/cc    -o CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o   -c /git/opencv/samples/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_26f76
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_26f76.dir/link.txt --verbose=1
/usr/bin/cc      -rdynamic CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o  -o cmTC_26f76
make[1]: Leaving directory '/git/opencv/samples/CMakeFiles/CMakeTmp'


Detecting C compiler ABI info compiled with the following output:
"/git/opencv/samples/CMakeFiles/CMakeOutput.log" 706 lines, 48095 characters
    Feature record: CXX_FEATURE:0cxx_defaulted_move_initializers
    Feature record: CXX_FEATURE:0cxx_delegating_constructors
    Feature record: CXX_FEATURE:0cxx_deleted_functions
    Feature record: CXX_FEATURE:0cxx_digit_separators
    Feature record: CXX_FEATURE:0cxx_enum_forward_declarations
    Feature record: CXX_FEATURE:0cxx_explicit_conversions
    Feature record: CXX_FEATURE:0cxx_extended_friend_declar
   etc ..

What is the correct way to build these examples - hopefully using the CMakeLists.txt already provided?

1 Answers

It seems the installation directory of OpenCV couldn't be found by cmake. Try to provide the value through the argument:

cmake -DCMAKE_PREFIX_PATH=/home/someone/src/opencv/install ..

Ff it works, you could define this in the top-level CMakeLitst.txt:

list(APPEND CMAKE_PREFIX_PATH /home/someone/src/opencv/install)

This should provide CMake the place where it should look to.

Related