无法使用OpenCV编译c ++程序。 OpenCVConfig.cmake文件丢失

时间:2019-02-13 15:33:17

标签: c++ macos opencv cmake

试图从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. 

尝试了一些解决方案,但没有任何帮助。 OpenCV已安装到macOS上的用户目录中。有人可以帮我吗?

2 个答案:

答案 0 :(得分:0)

当我尝试运行在其他系统上编写的程序时,Windows中的CLion也有类似的问题。为了解决该问题,我不得不“从源代码导入项目”,以便CLion生成Make所需的所有文件。

我通过导入后弹出的对话框导入了现有程序。

CLion Start-up Window

这是我以CLion要求的方式导入存储库之前的简单GCD c ++终端程序:

GCD Project Files

选择导入后,CLion生成了在本地编译所需的所有文件:

My new project file architecture

我希望这对我有帮助,一旦导入程序,CLion就会完成其他所有工作。我为c ++ 11修改了CMakeList.txt文件,因为我需要知道程序可以按预期在11编译。CLion对我而言默认为c ++ 14。

答案 1 :(得分:0)

该错误消息清楚地说明了解决该问题的方法:首先,找到上述文件之一(df$Testdiff <- ifelse(with(df, ave(cost, ID, FUN = function(x) length(unique(x)))) > 1, "Y", "N") aggregate(.~ID, df, head, n = 1) # ID cost Testdiff #1 A 0.5 Y #2 B 0.7 Y #3 C 1.3 N #4 D 2.6 N OpenCVConfig.cmake)在系统上的位置。此路径将为opencv-config.cmake。然后相应地设置/path/to/configfile变量。

可以通过两种方式设置变量:

  • 命令行:OpenCV_DIR
  • CLion设置:请参阅以下图像(取自previous post)。但是除了向cmake -DOpenCV_DIR=</path/to/configfile> <any additional arguments>添加-DENABLE_TESTS=ON到CMake选项:

enter image description here

enter image description here

相关问题