cmake find_package 指定路径

cmake find_package specify path(cmake find_package 指定路径)
本文介绍了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 指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Bring window to front -gt; raise(),show(),activateWindow() don’t work(把窗户放在前面 -raise(),show(),activateWindow() 不起作用)
How to get a list video capture devices NAMES (web cameras) using Qt (crossplatform)? (C++)(如何使用 Qt(跨平台)获取列表视频捕获设备名称(网络摄像机)?(C++))
How to compile Qt as static(如何将 Qt 编译为静态)
C++ over Qt : Controlling transparency of Labels and Buttons(C++ over Qt:控制标签和按钮的透明度)
How to know when a new USB storage device is connected in Qt?(Qt如何知道新的USB存储设备何时连接?)
What is an event loop in Qt?(Qt 中的事件循环是什么?)