cmake find_package specify path(cmake find_package 指定路径)
问题描述
我的机器上安装了 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 指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cmake find_package 指定路径
基础教程推荐
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++,'if' 表达式中的变量声明 2021-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17