找不到模块 FindOpenCV.cmake(配置过程出错) [英] Could not find module FindOpenCV.cmake ( Error in configuration process)
问题描述
我为一个使用 OpenCV 库的 C++ 项目编写了一个 CMakeLists.txt
.当我尝试使用 cmake 创建项目时,我遇到了下一个配置问题:
I wrote a CMakeLists.txt
for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
Could not find module FindOpenCV.cmake or a configuration file for package
OpenCV.
Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
directory containing a CMake configuration file for OpenCV. The file will
have one of the following names:
OpenCVConfig.cmake
opencv-config.cmake
事实是,我在 Visual Studio 中使用的路径有一个环境变量,没有任何问题.如果我不包含OpenCV,那么我可以毫无问题地进行配置和生成,但是我需要解决问题.我不明白为什么 cmake 找不到 OpenCV 路径或如何修复它.
The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.
我还使用了此链接中提到的建议:FindOpenCV.cmake
I also used the recommendations mentioned in this link: FindOpenCV.cmake
有人也遇到过这个问题吗?
Does anybody had this problem too?
推荐答案
您看到的错误是 CMake 找不到 FindOpenCV.cmake 文件,因为 cmake 没有包含一个开箱即用的文件.因此,您需要找到一个并将其放在 cmake 可以找到的地方:
The error you're seeing is that CMake cannot find a FindOpenCV.cmake file, because cmake doesn't include one out of the box. Therefore you need to find one and put it where cmake can find it:
您可以在此处找到良好的开端.如果您喜欢冒险,也可以自己编写.
You can find a good start here. If you're feeling adventurous you can also write your own.
然后将其添加到项目中的某个位置并调整 CMAKE_MODULE_PATH 以便 cmake 可以找到它.
Then add it somewhere in your project and adjust CMAKE_MODULE_PATH so that cmake can find it.
例如,如果你有
CMakeLists.txt
cmake-modules/FindOpenCV.cmake
那你应该做一个
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
在执行 find_package(OpenCV) 之前在 CMakeLists.txt 文件中
In your CMakeLists.txt file before you do a find_package(OpenCV)
这篇关于找不到模块 FindOpenCV.cmake(配置过程出错)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!