Cmake not working in opencv c ++ project
I need your help! I have this C ++ code in this link
and I have been trying for two days to internalize it and I have failed they say I should use cmake, I tried the "GUI version and it gave me errors that were implemented by cmake itself". so I took the cpp and headers files and made a new project, but now I have 100 errors related to the opencv library and I swear to god. I'm pretty sure it includes folders and their libraries in my project! I don't know what is connected with this!
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 '
source to share
So this is what fixed it for me.
First, when in doubt, always remember to clear the CMake cache before trying to add some other path / value / mod . It seems a little odd that I know, but the legacy of previous attempts to fix the situation may take the true problem. The easiest way to do this is to cut from your original "build" directory from orbit (just to be sure) and try again ...
Second, and mostly, what is your target compiler and architecture here and what is provided by the version of the downloaded OpenCV? For example, at the time of writing, OpenCV 3.1, the pre-built installer I downloaded provides
~\build\x64\vc12 & vc14
- which of course were built against VisualStudio 2012 and 2014.
I used Mingw and targeting x86 - so I downloaded the source (via github release as a file
) and took these steps from the folder
mkdir build cd build cmake -G "MinGW Makefiles" .. cmake --build . cmake --build . --target install
Of course, you can manage the assembly of various switches and also determine where the installation should go.
Performing the "install" step - by default - copying final libraries, etc. to a folder named "install" is the key, as it correctly places all the resulting libraries and files in the right place and includes the magic
file at the top.
This way I could finally tell my CMakeLists.txt project to resolve OpenCV with
set("OpenCV_DIR" "C:/Code/opencv/build/install") find_package( OpenCV REQUIRED )
And making sure the resulting executable knew about the * .dll with:
source to share
On Linux I did the following:
$ git clone https://github.com/royshil/FoodcamClassifier.git $ cd FoodcamClassifier/ $ mkdir build $ cd build/ $ cmake ../ -- The C compiler identification is GNU -- The CXX compiler identification is GNU -- Check for working C compiler: /usr/bin/gcc -- Check for working C compiler: /usr/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done /usr/local/share/OpenCV -- Configuring done -- Generating done -- Build files have been written to: /home/cog/workspace/opencv/FoodcamClassifier/build $ make Scanning dependencies of target build-vocabulary [ ] Building CXX object CMakeFiles/build-vocabulary.dir/build_vocabolary.cpp.o Linking CXX executable build-vocabulary [ ] Built target build-vocabulary Scanning dependencies of target foodcam-predict [ ] Building CXX object CMakeFiles/foodcam-predict.dir/foodcam_predict.cpp.o [ ] Building CXX object CMakeFiles/foodcam-predict.dir/predict_common.cpp.o Linking CXX executable foodcam-predict [ ] Built target foodcam-predict Scanning dependencies of target kmeans-trainer [ ] Building CXX object CMakeFiles/kmeans-trainer.dir/kmeans_trainer.cpp.o Linking CXX executable kmeans-trainer [ ] Built target kmeans-trainer Scanning dependencies of target make-test-background [ ] Building CXX object CMakeFiles/make-test-background.dir/make_test_background_image.cpp.o Linking CXX executable make-test-background [ ] Built target make-test-background Scanning dependencies of target manual-classifier [ ] Building CXX object CMakeFiles/manual-classifier.dir/manual_classifier.cpp.o Linking CXX executable manual-classifier [ ] Built target manual-classifier Scanning dependencies of target test-classifiers [ ] Building CXX object CMakeFiles/test-classifiers.dir/test_classifiers.cpp.o [ ] Building CXX object CMakeFiles/test-classifiers.dir/predict_common.cpp.o Linking CXX executable test-classifiers [ ] Built target test-classifiers Scanning dependencies of target train-SVM-alone [ ] Building CXX object CMakeFiles/train-SVM-alone.dir/train_SVM_alone.cpp.o [ ] Building CXX object CMakeFiles/train-SVM-alone.dir/training_common.cpp.o Linking CXX executable train-SVM-alone [ ] Built target train-SVM-alone Scanning dependencies of target train-bovw [ ] Building CXX object CMakeFiles/train-bovw.dir/train_bovw.cpp.o [ ] Building CXX object CMakeFiles/train-bovw.dir/training_common.cpp.o Linking CXX executable train-bovw [ ] Built target train-bovw
source to share
For me on Windows, I got a similar error message when I ran batch scripts with an open file editor (Atom). Don't assume the original question mentions OS and I'm pretty sure my problem is Windows related.
Although the OS is implied by the URL in the sample code.
If it's not a file descriptor / editor issue, it's probably a permissions error.
source to share