Cmake使用已编译的OpenCV版本

时间:2016-06-11 16:39:19

标签: c opencv cmake

我编译了opencv-2.4.13版本,现在我想用cmake编译一个项目。

如果我这样做:

cmake_minimum_required(VERSION 3.5.1)
project(phase)
find_package(Opencv REQUIRED)
include_directories(INCLUDE_DIR include)
aux_source_directory(src SOURCE)
add_library(dct SHARED src/dct.c ${SOURCE}

我收到以下错误:

CMake Error at CMakeLists.txt:4 (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.

因此,我创建了一个名为cmake-modules的文件夹,并复制了已编译的OpenCV项目生成的OpenCVConfig.cmake文件。

然后:

cmake_minimum_required(VERSION 3.5.1)
project(phase)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
find_package(Opencv REQUIRED)
include_directories(INCLUDE_DIR include)
aux_source_directory(src SOURCE)
add_library(dct SHARED src/dct.c ${SOURCE})

但我仍然得到同样的错误。

如何包含.cmake文件以查找OpenCV?

1 个答案:

答案 0 :(得分:0)

我用以下方法解决了这个问题:

cmake_minimum_required(VERSION 3.5.1)
project(phase)
SET(OpenCV_INCLUDE_DIRS "/home/facu/opencv-2.4.13/include/opencv")
include_directories(INCLUDE_DIR include ${OpenCV_INCLUDE_DIRS})
set(OpenCV_LIB_DIR "/home/facu/opencv-2.4.13/release/lib")
link_directories(${OpenCV_LIB_DIR})
aux_source_directory(src SOURCE)
add_library(dct SHARED src/dct.c ${SOURCE})