OK, I know this is ancient but...had a similar problem, same error message.
There is a command under File on the GUI that cleans out the cache. This did not work the first time but eventually it did. I thrashed around a bit, adding cmake to the user path, reboot, don't know if any of that helped.
I got into trouble initially by trying to run cmake on a CMakeLists.txt that was NOT the root. This error popped up when I tried again with the proper source directory. V3.1.3.
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 ~\build\x64\vc12 & 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:\Code\opencv\build\install\x86\mingw\bin
Best Answer
What operating system are you on? Is it possible that you have the wrong kind of newline character in your file?
In all flavors of Windows (and DOS), the new line should be a carriage return (ASCII 13) and line feed (ASCII 10). On older Macs, the new line should be just a carriage return (ASCII 13). On Linux and Unix (including Mac OS X), the new line should be a line feed (ASCII 10).