使用cmake find_package找不到opencv

对cmake的使用不是很熟悉,遇到这个问题为自己简单记录一下。

错误如下:

CMake Error at CMakeLists.txt:39 (find_package):

  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时,不是使用的默认的路径,导致cmake找不到opencv

解决方法:

首先    export OpenCV_DIR=/usr/local/opencv-3.1.0

然后在build目录下执行  cmake  ..  即可

你可能感兴趣的:(编译库)