C++ cmake find_package 指定路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49816206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cmake find_package specify path
提问by Gerry
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:
我的机器上安装了 2 个版本的 OpenCV。一个在/usr/local/opencv3.1
. 我假设另一个(版本 3.4)的安装位置是/usr/local
. 无论如何,find_package(OpenCV 3.0 REQUIRED)
设置OpenCV_DIR:PATH=/usr/local/share/OpenCV
. 该文件夹包含:
haarcascades OpenCVConfig.cmake OpenCVModules-release.cmake
java OpenCVConfig-version.cmake valgrind_3rdparty.supp
lbpcascades OpenCVModules.cmake valgrind.supp
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:
在这种情况下,使用版本 3.4。如何在 CMakeLists.txt 中指定使用其他版本 (3.1) 知道其安装位置?我试过了:
find_package(OpenCV 3.0 REQUIRED PATH /usr/local/opencv3.1)
Which returns an error:
它返回一个错误:
Could NOT find OpenCV (missing: PATH /usr/local/opencv3.1) (found suitable version "3.4.1", minimum required is "3.0")
and
和
set(OpenCV_DIR /usr/local/opencv3.1/OpenCV/*) # also tried OpenCV_ROOT_DIR, OPENCV_ROOT_DIR
find_package(OpenCV 3.0 REQUIRED)
Which does nothing. It still finds version 3.4. I'd be grateful for any help. Thank you.
什么都不做。它仍然找到版本 3.4。我会很感激任何帮助。谢谢你。
回答by api55
In the find_package documentationyou 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 文档中,您可以设置要搜索的路径,而PATHS
您缺少 S...您也可以执行以下操作:
find_package (<package> PATHS paths... NO_DEFAULT_PATH)
find_package (<package>)
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.
这将检查您首先编写的路径,如果找到,则将 found 设置为 true 并跳过第二条指令。
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.
此外,您可以使用该EXACT
选项来匹配特定版本,以防它因版本较新而尝试选择 3.4。
find_package(OpenCV 3.1 EXACT REQUIRED PATHS /usr/local/opencv3.1)
I hope this helps, if not, write a comment
我希望这有帮助,如果没有,请写评论