在cmake工程中使用opencv需要在CMakeLists.txt文件中加以调用,在opencv2.xx版本,可以用以下语句

# 寻找OpenCV库
find_package( OpenCV REQUIRED ) # 添加头文件
include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable( xxx xxx.cpp ) # 链接OpenCV库
target_link_libraries( xxx ${OpenCV_LIBS} )

但如果你使用的是OpenCV 3.x版本,再用上面的方法就会报错

CMake Warning at /home/zn/opencv-3.1./cmake/OpenCVConfig.cmake: (message):
Found OpenCV Windows Pack but it has no binaries compatible with your
configuration. You should manually point CMake variable OpenCV_DIR to your build of OpenCV
library.
Call Stack (most recent call first):
CMakeLists.txt: (find_package) CMake Error at CMakeLists.txt: (find_package):
Found package configuration file: /home/zn/opencv-3.1./cmake/OpenCVConfig.cmake but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
NOT FOUND. -- Configuring incomplete, errors occurred!

从上面的报错可以看出在OpenCVConfig.cmake文件中设置OpenCV_FOUND to FALSE,故find_package( OpenCV REQUIRED )是不可用的。我认为这是opencv3.x版本对opencv2.x版本的屏蔽,以防混用。要使用opencv3.x需要用如下语句

# 寻找OpenCV库  我的版本的opencv3.1.0
find_package( OpenCV 3.1 REQUIRED ) # 添加头文件
include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable( xxx xxx.cpp ) # 链接OpenCV库
target_link_libraries( xxx ${OpenCV_LIBS} )

也就是要加上opencv对应的版本号就可以解决报错了。

opencv3在CMakeLists.txt中的调用问题的更多相关文章

  1. 在ros功能包CMakeLists.txt中获取所在功能包的路径 便于添加第三方库的相对路径

    在 ros 功能包中要使用第三方的动态库,将其放在系统默认库路径和使用绝对路径均不可取,这样的话可移植性较差,将该功能包移到其它电脑时要重新配置依赖库的路径,太麻烦了. 于是找到下面这个方法,解决了R ...

  2. cmakelists.txt中配置openg环境出现: undefined reference to symbol 'glLightfv'

    cmakelists.txt中配置openg环境出现: undefined reference to symbol 'glLightfv' 解决方法: 在cmakelists.txt添加 find_p ...

  3. Cmakelists.txt中配置glew

    在cmakelists.txt中添加: add_library(glew_static STATIC IMPORTED) set_target_properties(glew_static PROPE ...

  4. Cmakelists.txt中配置glfw

    qt中需要用cmake编译工程,且需要用到OpenGL库glfw,如何给Cmakelist.txt配置glfw的动态链接库? 在Cmakelists.txt添: find_package(glfw3 ...

  5. CMakeLists.txt中使用循环

    编译一个安卓下的so,此so依赖其他的库,通过循环简化操作 set(UVC_LIBS UVCCamera uvc usb100 jpeg-turbo1500) FOREACH(UVC_LIB ${UV ...

  6. Ros学习——Cmakelists.txt文件解读

    1.过程 .Required CMake Version (cmake_minimum_required) //CMake 需要的版本 .Package Name (project()) //#定义工 ...

  7. linux CMakeLists.txt 语法

    CMake入门教程 参考文献:http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/index.html 官方网址:http://www.cmak ...

  8. CMake之CMakeLists.txt编写入门

    自定义变量 主要有隐式定义和显式定义两种. 隐式定义的一个例子是PROJECT指令,它会隐式的定义< projectname >_BINARY_DIR和< projectname & ...

  9. CMakeLists.txt install

    本部分是关于ros CMakeLists.txt install  :可参考http://wiki.ros.org/catkin/CMakeLists.txt 1.CMakeLists.txt中的in ...

随机推荐

  1. Java 流(Stream)、文件(File)和IO -- Java ByteArrayInputStream类

    字节数组输入流在内存中创建一个字节数组缓冲区,从输入流读取的数据保存在该字节数组缓冲区中.创建字节数组输入流对象有以下几种方式. 接收字节数组作为参数创建: ByteArrayInputStream ...

  2. WAMP运行分析

  3. numpy, pandas, matplotlib等常用库的学习手册

    pandas介绍: 待续 参考资料: 中文:https://www.cnblogs.com/skying555/p/5914391.html 英文:http://www.datadependence. ...

  4. jquery 复制文本到剪切板插件(非 flash)

    原创插件,转载请声明出处!!! jquery.copy.js 内容如下: /*! * jQuery Copy Plugin * version: 1.0.0-2018.01.23 * Requires ...

  5. laravel 5.3升级5.4

    1)修改 composer 配置文件 composer.json 1.如果你用了 laravel-admin,larvel-admin 版本改 1.4.x-dev 2.laravel 版本改 5.4. ...

  6. 我的WAF Bypass实战系列

    ​ 梳理了一下自己写过的WAF Bypass相关的文章,按照编写时间顺序,整理成了一个WAF Bypass实战系列,如果你准备了解WAF攻防这一块的内容,可以来了解一下. 第一篇:<Bypass ...

  7. 【LeetCode OJ】Two Sum

    题目:Given an array of integers, find two numbers such that they add up to a specific target number. T ...

  8. linux源码编译安装php出现 cannot find -lltdl

    原因: 在编辑php时添加的“–with-mcrypt”选项造成. 解决方法: 1.如果不需要mcrypt,那么编辑php时去掉该选项,然后再make.make install. 2.如果需要mcry ...

  9. python下安装Scikit-learn

    安装SK-Learn需要依赖的Python安装包有: Python (>= 2.6), NumPy (>= 1.3), SciPy (>= 0.7), 下载python的各种包的地址 ...

  10. Android设计和开发系列第二篇:Navigation Drawer(Develop)

    Creating a Navigation Drawer THIS LESSON TEACHES YOU TO: Create a Drawer Layout Initialize the Drawe ...