Zheng
Zheng

Reputation: 93

CMake cannot find OpenCVConfig.cmake even after specifying OpenCV_DIR

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?

Upvotes: 0

Views: 1405

Answers (1)

Alex Reinking
Alex Reinking

Reputation: 19916

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.

Upvotes: 1

Related Questions