CMake没有找到OpenCV

时间:2016-11-02 14:17:04

标签: opencv cmake

我的CMakeLists和opencv似乎有问题。 我目前正在使用opencv 2.4版本,该版本由

确认
pkg-config --modversion opencv

2.4.8

dpkg -l libopencv*

输出http://pastebin.com/ZJEfLjDX

但出于某种原因,当我cmake一个简单的程序,如

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    Mat image;
    image = imread( argv[1], 1 );

    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);

    waitKey(0);

    return 0;
}

由于此错误,cmake将无法继续。

CMake Error at /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake:183 (message):
  The imported target "opencv_core" references the file

     "/opt/ros/indigo/lib/libopencv_core3.so.3.1.0"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVModules.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake:86 (include)
  CMakeLists.txt:3 (find_package)


-- Configuring incomplete, errors occurred!

使用此CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

该项目没有ros依赖项,我不知道为什么它在OpenCVConfig.cmake内寻找ros

简单的locate表示正确的版本可用于其他地方

locate OpenCVConfig.cmake

/home/k/opencv/opencv-2.4.8/build/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/build/unix-install/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/OpenCVConfig.cmake
/home/k/opencv/opencv-2.4.8/cmake/templates/OpenCVConfig.cmake.in
/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake
/usr/local/share/OpenCV/OpenCVConfig.cmake
/usr/share/OpenCV/OpenCVConfig.cmake

但是为什么它会选择使用ros中的那个,如果我没有安装opencv3.1.0-dev,我甚至不确定这是一个选项?

我知道这个问题的解决方案是SET路径。但为什么find_package无法使用2.4.8版本?我甚至尝试将/ opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake的文件名更改为/opt/ros/indigo/share/OpenCV-3.1.0-dev/OpenCVConfig.cmake.old,导致同样的错误?...为什么cmake无法通过简单的{opencv找到find_package( OpenCV REQUIRED ) {1}},我如何制作它以便可以使用它来查找。

0 个答案:

没有答案