Windows CMake configure unable to find OpenCV_DIR
Closed this issue · 9 comments
Error output on configure:
CMake Error at CMakeLists.txt:28 (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 built and installed from source, which path should I specify for OpenCV_DIR ?
@austinbeauch the path to your OpenCVConfig.cmake file that you should have got during the build.
If you're on Windows, it's usually somewhere in the build output folder [Edit: and installation folder where the opencv_world.dll is].
@Algomorph thanks for the quick reply. Now I'm running into a Boost issue where CMake can't find the static libraries...
Boost version: 1.65.0
Boost include path: C:\local\boost_1_65_0
Could not find the following static Boost libraries:
boost_python-py36
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
I installed the prebuilt binaries to C:\local\boost_1_65_0
(I am on Windows unfortunately), with boost_python3-vc141-mt-gd-1_65.dll/lib
etc under C:\local\boost_1_65_0\lib64-msvc-14.1
.
Ever encounter something similar? Boost_DIR
and its PY36
debug/release entries are not found in CMake, if that makes any difference.
@austinbeauch try some kind of bulk renamer, for instance maybe this one, to rename your boost_.lib / .dll files into libboost_.lib files (literally, make a copy of the whole folder, rename inside that folder, than merge with the original folders, so you have both naming variants just in case). I thought I solved this problem a little while ago with special CMake commands for Windows, where boost builds without the "lib" prefix, but maybe it didn't quite cut it for some reason. The manual renaming is a crude workaround, but I know it works.
[Edit] Before you do that, have you tried manually specifying the entries for the boost libraries in CMake-GUI? Perhaps it's just missing this BOOST_LIBRARYDIR which you can set manually.
@Algomorph under the \lib64-msvc-14.1\
directory there's also the libboost_python3-vc141*.lib files (asterisk because there's a few different variants). I tried setting BOOST_LIBRARYDIR by adding an entry and pointing it to \lib64-msvc-14.1\
but same error as above, can't find the static libraries... what exactly does the static Boost Python file look like? Could the various naming schemes with my prebuilt be different than what CMake is expecting to find?
Also should probably menion that Boost_DIR is not found and i'm not 100% what path it should be set to.
@austinbeauch The .lib files are the static libraries, the python one should have the word "python" in it, if I recall correctly (at the very least the "py" prefix). Yes, the minimal build (I think) doesn't include the python one, so when you build the boost libraries, make sure you either build all of them or that you specify the appropriate argument for the python one. I don't remember what the b2 arguments are off the top of my head, but you should be able to easily find how to do the complete build in the Boost build instructions.
I also got this "problem" on windows... I overcame it by modifying the CMakeLists.txt file, line 43 from:
**_find_package(Boost COMPONENTS python-py${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR} REQUIRED)_**
to:
**_find_package(Boost COMPONENTS python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR} REQUIRED)_**
that is to say "-py" had been removed.
@OreneElmaleh , thank you so much, I'll look into this. @austinbeauch Let's keep this issue open, it will serve as a reminder for me.
Finally got it to work! Thank you both big time, @Algomorph and @OreneElmaleh.
What I ended up doing top to bottom (this is for future reference in case anyone else runs into this issues):
- built OpenCV from source, created user variable OpenCV_DIR with value
C:\Users\User\Downloads\opencv\build
- built 64bit Boost.Python (1.67 in my case) for python 3.6.
- moved .ddl/.lib files from
.../boost_1_76_0/stage/lib/
to a new folder../boost_1_67_0/lib64-msvc-14.1
(I don't know if this actually makes a difference but it worked and I'm scared to change it) - copied all boost_* files and renamed them to libboost_*, keeping both flavors in
/lib64-msvc-14.1
- change the
python-py
topython
on line 43 of CMakeLists.txt in\pyboostcvconverter
- set
Boost_DIR
to.../boost_1_67_0
in CMake, where it was able to find the static libraries and generate properly - open built .sln file, build, install
- add
../boost_1_67_0/lib64-msvc-14.1
to user PATH, so the .pyd file can find the binaries.
@austinbeauch thank you for providing your work-around. It may be very helpful for people who encounter the same issue.