[英]Can't compile c++ program with OpenCV. OpenCVConfig.cmake file missing
Tried to run my simple cpp program from CLion and also from terminal, but everywhere have the same problem:试图从 CLion 和终端运行我的简单 cpp 程序,但到处都有同样的问题:
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
Tried some solutions, but nothing helped.尝试了一些解决方案,但没有任何帮助。 OpenCV is installed into user directory on macOS.
OpenCV 安装在 macOS 上的用户目录中。 Could someone help me?
有人可以帮助我吗?
I had a similar issue with CLion in Windows when I tried to run a program I wrote on a different system. 当我尝试运行在其他系统上编写的程序时,Windows中的CLion存在类似的问题。 To fix the problem I had to "Import Project from Sources" so that CLion would generate all the necessary files for Make.
为了解决该问题,我不得不“从源代码导入项目”,以便CLion生成Make所需的所有文件。
I imported the existing program through the dialog box that popped up after I Imported. 我通过导入后弹出的对话框导入了现有程序。
This was my simple GCD c++ terminal program before I imported the repo the way CLion required me to: 这是我以CLion要求的方式导入存储库之前的简单GCD c ++终端程序:
After I chose import CLion generated all the files necessary to compile locally: 选择导入后,CLion生成了在本地编译所需的所有文件:
I hope this helps, once I got my program imported CLion did everything else. 我希望这对我有帮助,一旦导入程序,CLion便会执行其他所有操作。 I modified my CMakeList.txt file for c++11 because I need to know my programs compile as expected on 11. CLion defaulted to c++14 for my.
我修改了c ++ 11的CMakeList.txt文件,因为我需要知道我的程序可以按预期在11上编译。CLion对我而言默认为c ++ 14。
The error message clearly states, what to do to resolve it: First, find where one of the mentioned files ( OpenCVConfig.cmake
or opencv-config.cmake
) is located on your system. 该错误消息清楚地指出了解决该问题的方法:首先,找到上述文件之一(
OpenCVConfig.cmake
或opencv-config.cmake
)在您系统上的位置。 This path will be /path/to/configfile
. 该路径将是
/path/to/configfile
。 Then set the OpenCV_DIR
variable accordingly. 然后相应地设置
OpenCV_DIR
变量。
Setting the variable can be done in two ways: 可以通过两种方式设置变量:
cmake -DOpenCV_DIR=</path/to/configfile> <any additional arguments>
cmake -DOpenCV_DIR=</path/to/configfile> <any additional arguments>
-DENABLE_TESTS=ON
add -DOpenCV_DIR=</path/to/configfile>
to CMake options: -DENABLE_TESTS=ON
可以将-DOpenCV_DIR=</path/to/configfile>
到CMake选项: As the error message says:正如错误消息所说:
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files.
So look for the file OpenCVConfig.cmake
and in your CMakeLists.txt
file set the variable OpenCV_DIR
to the directory containing the OpenCVConfig.cmake
file.因此,查找文件
OpenCVConfig.cmake
并在您的CMakeLists.txt
文件中将变量OpenCV_DIR
设置为包含OpenCVConfig.cmake
文件的目录。
In my case I had installed opencv from the source.就我而言,我从源代码安装了 opencv。 The directory where I had installed opencv had the following structure
我安装opencv的目录结构如下
opencv-installation-directory/
- bin/
- include/
- lib/
- share/
- OpenCV/
- OpenCVConfig.cmake
So I added the following line to CMakeLists.txt
:所以我
CMakeLists.txt
下行添加到CMakeLists.txt
:
set(OpenCV_DIR opencv-installation-directory/share/OpenCV)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.