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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…