[英]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.我正在使用 OpenCV 运行 C++ 程序。我已经安装了所有必需的库,但似乎 cmake 找不到 OpenCV 库。
The command port content opencv3
shows my opencv libraries are under these folders:命令port content opencv3
显示我的 opencv 库位于这些文件夹下:
/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.但是在find_package(OpenCV REQUIRED)
之前添加set(OpenCV_DIR /opt/local)
不起作用,并且每次都会弹出相同的错误。
What should I do?我应该怎么办?
CMake commands do not separate their arguments via ,
. CMake 命令不会通过,
分隔它们的 arguments。 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
.实际上,您将名为OpenCV_DIR,
的变量设置为/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.您的 CMakeLists.txt 应该没有绝对路径。 Instead, set -DCMAKE_PREFIX_PATH=/opt/local
on the command line or in apreset .相反,在命令行或预设中设置-DCMAKE_PREFIX_PATH=/opt/local
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.