简体   繁体   English

Cmake在ubuntu 18.04上找不到本地版本的opencv

[英]Cmake can not find local version of opencv on ubuntu 18.04

I have a version of OpenCV ((3.4.1) compiled and installed in /home/m/locals/opencv我有一个版本的 OpenCV ((3.4.1) 编译并安装在 /home/m/locals/opencv

the content of /home/m/locals/opencv is: /home/m/locals/opencv 的内容是:

bin
include
lib
share

I have an eniroment pointing to this directory:我有一个指向这个目录的环境:

echo $OPENCV_ROOT
/home/m/locals/opencv

I have a cmake that tries to add opencv to project:我有一个尝试将 opencv 添加到项目的 cmake:

 file(TO_CMAKE_PATH $ENV{OPENCV_ROOT} OpenCV_DIR)
 set(BUILD_SHARED_LIBS OFF)
 find_package(OpenCV  COMPONENTS core highgui imgproc imgcodecs videoio photo stitching flann ml features2d calib3d objdetect REQUIRED)

when I run cmake, I am getting this error:当我运行 cmake 时,我收到此错误:

CMake Error at /usr/local/share/OpenCV/OpenCVModules.cmake:399 (message):
The imported target "opencv_core" references the file

     "/usr/local/lib/libopencv_core.so.3.4.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

      "/usr/local/share/OpenCV/OpenCVModules.cmake"

   but not all the files it references.

My questions:我的问题:

  1. Why it is trying to find OpenbCV 3.4.0, when the one that i installed is 3.4.1为什么它试图找到 OpenbCV 3.4.0,而我安装的是 3.4.1
  2. How can I fix it and make msure that it points to the correct copy of openCV?如何修复它并确保它指向正确的 openCV 副本?

You can do export OpenCV_DIR=... as commented by @Tsyvarev. 您可以按照export OpenCV_DIR=... However, it may affect other builds that requires exactly 3.4.0 . 但是,它可能会影响其他需要3.4.0 Rather, set the variable in your project's CMakeLists.txt 而是在项目的CMakeLists.txt设置变量

set(OpenCV_DIR /home/m/locals/opencv/share/OpenCV)

or, you can set the variable manually when running cmake: 或者,您可以在运行cmake时手动设置变量:

cmake -D OpenCV_DIR=/home/m/locals/opencv/share/OpenCV ..

I solved this problem by fully removing OpenCV and build it from the source.我通过完全删除 OpenCV 并从源代码构建它来解决这个问题。 This helped me to install OpenCV 3.3 in ubuntu 18.04 帮助我在 ubuntu 18.04 中安装了 OpenCV 3.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM