pkg-config opencv --modversion is not OK
pkg-config opencv4 --modversion is OK
可以看到在执行 find_package(OpenCV 3 REQUIRED) 命令后,CMake 找到了我们安装的位于 /usr/local 下的 OpenCV 库,并设置了 CMake 变量 OpenCV_DIR 为 OpenCV 库的配置文件所在路径,正是通过载入这个路径下的 OpenCVConfig.cmake 配置文件才能配置好 OpenCV 库,然后在 OpenCVConfig.cmake 配置文件中定义了变量 OpenCV_INCLUDE_DIRS 为 OpenCV 库头文件包含路径,这样我们才能才在代码中使用
- down load source code
- cmake && make
- if applying “sudo make install”, then the “OpenCVConfig.cmake” under /usr/local/ will be replaced by the contemporary one
and the version certainly will depends on that file.
if it is found anoiy, then just using set(OpenCV_DIR “path to opencv source /build”) could be used the same function as find_package(OpenCV xx REQUIRED).
The alternative method could also applied on windows while the first method(find_package) could not. It is because “make install” performs differently on ubuntu/windows, one can replace or put certain version under /usr/local while another just create one direct under build and still relied on the set() command.
as you can see in opencv build, there is OpenCVconfig.cmake, and in cmake.install.cmake there is:
set(CMAKE_INSTALL_PREFIX "/usr/local")
indicating that the folder of libs in ubuntu system.