Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
734 views
in Technique[技术] by (71.8m points)

c++ - cmake find_package specify path

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

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)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...