2

I am having an issue building a project using Cmake, which I have never done before. I am new to C++ and the concept of Cmake and Makefiles. I am trying to recreate some results from some code off of GitHub. The instructions/files can be found here if you would like to take a more detailed look:

https://github.com/jan-dufek/Fotokite

So basically there are four steps he lists to do:

1-)Install CMake:

https://cmake.org

2-) In Terminal, change directory into the root directory of the project and run the following command to generate makefile:

cmake .

3-) Compile the project:

make

4-) Run:

./Fotokite


Basically I am stuck on the 2nd step right now because I keep getting the following error in my terminal after navigating to the folder and running "cmake .".

The C compiler identification is AppleClang 11.0.3.11030032
The CXX compiler identification is AppleClang 11.0.3.11030032
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped     
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.


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.

I have OpenCV downloaded onto my Desktop as well, and I tried incorporating the path into the Cmake file but still am not having any luck.

Here is also the Cmakelists.txt:

cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
project(Fotokite)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
file(GLOB SOURCES
*.h
*.hpp
*.cpp
)
list(FILTER SOURCES EXCLUDE REGEX "main.*.cpp")
list(FILTER SOURCES EXCLUDE REGEX "Visualization.*")
foreach (FILE "" Takeoff GoToWaypoint ExecutePath Land)
add_executable(Fotokite${FILE} ${SOURCES} main${FILE}.cpp)
target_link_libraries(Fotokite${FILE} ${OpenCV_LIBS} pthread)
endforeach(FILE)

First time posting on this website so sorry if something is unclear, if so I can provide more details! Looking forward to your responses.

5
  • 1
    The key to solving this is follow the advice of the error message. It tells you exactly what to do: set "OpenCV_DIR" to a directory containing one of the above files. You can do this in CMake-Gui or ccmake or via the -D command line option to cmake Commented Oct 15, 2020 at 20:20
  • thanks, I went ahead and put the opencv directory into my project folder and configurated/generated the build! Now I am on the 3rd step where I ran "make" and its been building for the past 30 minutes. Is this typical for the build to take this long?? Commented Oct 15, 2020 at 21:08
  • Could be depending on the project and how many cores your machine has. Commented Oct 15, 2020 at 21:09
  • So I got it to build 100 percent after running $make but now I am confused as to running the individual files in the project folder. I ran g++ Fotokite.cpp in the terminal but now I am having the issue 'opencv2/core.hpp'. Is there a specific command I should be using after running $make to run the files in the folder Commented Oct 15, 2020 at 23:12
  • I think the problem was created by copying the opencv source to the project directory. You probably wanted to build OpenCV separately using CMake. Commented Oct 15, 2020 at 23:25

2 Answers 2

1

The following error message details the cause of the issue:

CMake Error at CMakeLists.txt:5 (find_package): By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "OpenCV", but CMake did not find one.

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.

What this means is that when the call to find_package is made, CMake has two modes to finding dependencies, “Module” mode and “Config” mode. Module mode means that somewhere on CMakes modules path it can find a file called FindOpenCV.cmake. By default CMake ships with lots of preprepared find modules, however, it does not ship with one for OpenCV by default. In this case, you could add it your self (just google for FindOpenCV.cmake and you'll find examples) however this in the wrong approach, I'll explain why.

When you produce a library build using CMake, if you expect to have downstream clients who will depend on your library then you should make it easy to use. CMake supports this through “Config” mode. When you write a library using CMake as part of the install step (this is the step that can be run to package a library into an installable set of files and folder structure after building). You can see an example of how to set this up for a project here: https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-to-create-a-ProjectConfig.cmake-file. At this point you don't need to know how to do this, just that libraries should do this because they have the information to export targets for a library correctly. If they don't then it become necessary for users to access a library in “Module” mode, which involved creating a find<library>.cmake which instruction detailing how to locate the file.

However, OpenCV using CMake does thankfully correctly create and install a OpenCVConfig.cmake file allowing users to use “Config” mode to access it. There issue here then seems that you have not installed OpenCV into one of the standard system install directories which “Config” mode searched by default. The list of search locations is detailed here: https://cmake.org/cmake/help/v3.19/command/find_package.html. To fix this you can pass in the PATH parameter to find_package so that it looks in additional locations:

find_package(OpenCV REQUIRED PATH <location to OpenCV installation>)
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your response! I figured out that using brew install solved this problem!
Fantastic, glad you've resolved it! Yes, brew install will place a copy in the system install location which CMake should be able to find by default.
0

I have seen similar issue while using buildroot to build something.

when I check the log, found

>>> xxxxxx Configuring
>>> xxxxxx Installing to target
xxxxxxxxxxxxxx  DESTDIR= xxxxxxxxxxxxxxx

please take a close look at the DESTDIR variable. it might be impacted by "FOO_INSTALL_STAGING = YES" command in xxx.mk file.

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.