Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

cmake is not working in opencv c++ project

I need your help ! I have this C++ code in this link

[link] https://github.com/royshil/FoodcamClassifier

and I've been trying since two days to compaile it , and I've failed they say that I have to use cmake , I've tried the "GUI version and it gave me errors realted to the cmake itself . so I took the cpp and header files and made a new project but I have now 100 errors related to the opencv library and I swear to god I'm sure of the include folders and the libs of it in my project ! don't know what's the matter with it !

any idea ?

Here's the errors :

'CMake Error: Unable to open cache file for save. C:/Program Files/CMake 2.8/bin/CMakeCache.txt
CMake Error at CMakeLists.txt:4 (FIND_PACKAGE):
  Could not find module FindOpenCV.cmake or a configuration file for package
  OpenCV.

  Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
  directory containing a CMake configuration file for OpenCV.  The file will
  have one of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake



OpenCV_DIR-NOTFOUND
Configuring incomplete, errors occurred!
CMake Error: Unable to open cache file for save. C:/Program Files/CMake 2.8/bin/CMakeCache.txt
CMake Error: : System Error: Permission denied
CMake Error: : System Error: Permission denied '
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So, this is what fixed this for me.

Firstly, if in doubt - always remember to clear out your CMake "cache" before trying adding some-other path/value/mod. Seems a bit weird I know, but the legacy of previous attempts to fix things may be obsuring the true problem. Simplest way to do this is to nuke your out-of-source "build" directory from orbit (only way to be sure) and try again...

Secondly, and more fundamentally, what is your target compiler & architecture here and what is provided by the version of OpenCV you've downloaded? For example, as of the time of writing the OpenCV 3.1 pre-built installer I downloaded provides ~uildx64vc12 & vc14 - which were of course for building against VisualStudio 2012 & 2014.

I was using Mingw and targeting x86 - so I downloaded the source (via github release as a *.zip file) and did these steps from within the opencv folder:

mkdir build
cd build
cmake -G  "MinGW Makefiles" ..
cmake --build .
cmake --build . --target install

You can of course control the build by various switches and also dictate where an install should go.

Doing the "install" step - by which by default is to copy the final libraries etc. into a folder called "install" - is key as it correctly puts all the resulting libs and files in the right place and includes the magical OpenCVConfig.cmake file at the top.

Thus, I could finally point my project CMakeLists.txt file to resolve OpenCV with:

set("OpenCV_DIR" "C:/Code/opencv/build/install")

find_package( OpenCV REQUIRED )

And, making sure the resulting executable was aware of the *.dll's with:

PATH=%PATH%;C:Codeopencvuildinstallx86mingwin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...