我的机器上安装了 2 个版本的 OpenCV.一个在 /usr/local/opencv3.1
中.我假设另一个(版本 3.4)的安装位置是 /usr/local
.无论如何,find_package(OpenCV 3.0 REQUIRED)
设置 OpenCV_DIR:PATH=/usr/local/share/OpenCV
.该文件夹包含:
I have 2 versions of OpenCV installed on my machine. One is in /usr/local/opencv3.1
. I presume the install location of the other one (version 3.4) is /usr/local
. Anyway, find_package(OpenCV 3.0 REQUIRED)
sets OpenCV_DIR:PATH=/usr/local/share/OpenCV
. This folder contains:
haarcascades OpenCVConfig.cmake OpenCVModules-release.cmake
java OpenCVConfig-version.cmake valgrind_3rdparty.supp
lbpcascades OpenCVModules.cmake valgrind.supp
在这种情况下,使用版本 3.4.如何在 CMakeLists.txt 中指定使用其他版本 (3.1) 知道其安装位置?我试过了:
In this case, version 3.4 is used. How can I specify in CMakeLists.txt to use the other version (3.1) knowing its install location? I've tried:
find_package(OpenCV 3.0 REQUIRED PATH /usr/local/opencv3.1)
返回错误:
Could NOT find OpenCV (missing: PATH /usr/local/opencv3.1) (found suitable version "3.4.1", minimum required is "3.0")
和
set(OpenCV_DIR /usr/local/opencv3.1/OpenCV/*) # also tried OpenCV_ROOT_DIR, OPENCV_ROOT_DIR
find_package(OpenCV 3.0 REQUIRED)
什么都不做.它仍然找到版本 3.4.我会很感激任何帮助.谢谢.
Which does nothing. It still finds version 3.4. I'd be grateful for any help. Thank you.
在 find_package 文档 你可以设置一个路径来搜索 PATHS
你错过了 S ... 你也可以做这样的事情:
In the find_package documentation you have that you can set a path to be searched with PATHS
you were missing the S... also you can do something like:
find_package (<package> PATHS paths... NO_DEFAULT_PATH)
find_package (<package>)
这将检查您首先编写的路径,如果找到,则将 found 设置为 true,并跳过第二条指令.
Which will check for the path you wrote first, the if it is found it will set found to true and the second instruction will be skipped.
此外,您可以使用 EXACT
选项来匹配特定版本,以防它因版本较新而尝试选择 3.4.
Also, you can use the EXACT
option to match an specific version, in case it tries to select 3.4 due to being a newer version.
find_package(OpenCV 3.1 EXACT REQUIRED PATHS /usr/local/opencv3.1)
希望对你有帮助,如果没有,请写评论
I hope this helps, if not, write a comment
这篇关于cmake find_package 指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!