0

I'm running a C++ program using OpenCV. I've installed all necessary libraries but it seems cmake cannot find OpenCV libraries.

The command port content opencv3 shows my opencv libraries are under these folders:

/opt/local/libexec/

/opt/local/bin/

/opt/local/lib/

/opt/local/include/

but adding set(OpenCV_DIR /opt/local) before find_package(OpenCV REQUIRED) didn't work and the same error just pop up every time.

What should I do?

2
  • Not set(OpenCV_DIR /opt/local). set(OpenCV_ROOT /opt/local), maybe. Commented Aug 21, 2021 at 19:48
  • I tried your solution, but unfortunatelly cmake reports the same error. Commented Aug 22, 2021 at 2:02

1 Answer 1

1

CMake commands do not separate their arguments via ,. Thus when you wrote:

set(OpenCV_DIR, /opt/local/share/OpenCV)

You in fact set a variable named OpenCV_DIR, to /opt/local/share/OpenCV. You can "fix" it by removing the comma:

set(OpenCV_DIR /opt/local/share/OpenCV)

I say "fix" because this is not a good way of doing things. Your CMakeLists.txt should be free of absolute paths. Instead, set -DCMAKE_PREFIX_PATH=/opt/local on the command line or in a preset.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, thanks for the answer. I just realized that locate is using some old cache and nothing really exists in the folder I mentioned in my previous question. I've just updated my question and please help me out. The program was able to run a few days ago before I upgraded the macOS system to a newer version, I've tried to reinstall the environment but it's always the same problem.
@Zheng: So, what is exact path to the OpenCVConfig.cmake file on your system? Without that file (or opencv-config.cmake one) OpenCV cannot be detected by CMake.
@Alex Reinking: After rebuilding the locate database, it turns out the exact path to OpenCVConfig.cmake is /opt/local/libexec/openvc3/cmake, and set(OpenCV_DIR /opt/local/libexec/openvc3/cmake) worked. I'd like to follow your advice, but I only have some experience with python and am really a noob with C++. I'm using CLion as my IDE and how can I set -DCMAKE_PREFIX_PATH=/opt/local on the command line as your recommendation? Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.