需要用到opencv依赖库的CMakeLists注意事项
2017-09-20 16:49
253 查看
1、find_package(OpenCV REQUIRED)中的OpenCV一定要遵循该大小写。
该句话是根据OpenCV作为前缀自动去/usr/local/share/OpenCV(如果你的opencv安装时,默认前缀设置为:/usr/local时)文件夹中去找OpenCVConfig.cmake,OpenCV-config.cmake 两个文件,进而确定你要引入的opencv头文件和库函数在哪里。
2、自定义引入相应opencv版本
如果你有很多的opencv版本,尤其是一个是opencv2.x.x一个是opencv3.x.x,因为2和3在数据结构上有相对较大的变化,所以如果引入错误的版本可能导致程序的无法运行。因为find_package找默认路径下的OpenCV,但是很多时候安装多个版本的库的时候都会make install在opt目录下。、
安装在opt的文件中会有share文件夹,这里面就有咱们需要的OpenCV文件夹,所以如果要自己有选择的控制版本,则在find_package这句话前面去设置opencv的OpenCV文件夹在哪里,添加set(OpenCV_DIR /opt/opencv-2.4.11/share/OpenCV)这句话。因为我的opencv2.4.11版本install在/opt/opencv-2.4.11文件夹下。这个可以根据你install的位置去变化。
# cmake needs this line cmake_minimum_required(VERSION 2.8) # Define project name project(opencvTest) # Find OpenCV, you may need to set OpenCV_DIR variable # to the absolute path to the directory containing OpenCVConfig.cmake file # via the command line or GUI find_package(OpenCV REQUIRED) # If the package has been found, several variables will # be set, you can find the full list with descriptions # in the OpenCVConfig.cmake file. # Print some message showing some of them message(STATUS "OpenCV library status:") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") # Add OpenCV headers location to your include paths include_directories(${OpenCV_INCLUDE_DIRS}) # Declare the executable target built from your sources add_executable(main main.cpp) # Link your application with OpenCV libraries target_link_libraries(main ${OpenCV_LIBS}) 如果多处编译需要依赖库,则需要给路径,set一下 # =================================================================================== # The OpenCV CMake configuration file # # ** File generated automatically, do not modify ** # # Usage from an external project: # In your CMakeLists.txt, add these lines: # # FIND_PACKAGE(OpenCV REQUIRED) # TARGET_LINK_LIBRARIES(MY_TARGET_NAME ${OpenCV_LIBS}) # # Or you can search for specific OpenCV modules: # # FIND_PACKAGE(OpenCV REQUIRED core highgui) # # If the module is found then OPENCV_<MODULE>_FOUND is set to TRUE. # # This file will define the following variables: # - OpenCV_LIBS : The list of all imported targets for OpenCV modules. # - OpenCV_INCLUDE_DIRS : The OpenCV include directories. # - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability # - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API # - OpenCV_VERSION : The version of this OpenCV build: "2.4.8" # - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION: "2" # - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION: "4" # - OpenCV_VERSION_PATCH : Patch version part of OpenCV_VERSION: "8" # - OpenCV_VERSION_TWEAK : Tweak version part of OpenCV_VERSION: "0" # # Advanced variables: # - OpenCV_SHARED # - OpenCV_CONFIG_PATH # - OpenCV_INSTALL_PATH (not set on Windows) # - OpenCV_LIB_COMPONENTS # - OpenCV_USE_MANGLED_PATHS # - OpenCV_HAVE_ANDROID_CAMERA # # ===================================================================================
相关文章推荐
- CMakeLists.txt添加opencv库注意事项
- CMakeLists.txt添加opencv库注意事项
- OpenCV3.2使用Cmake进行编译时注意事项
- 使用SQLServer2008R2进行缓存依赖通知需要注意事项
- 不定输入参数函数的编程中需要用到的宏,即注意事项
- AS使用NDK Cmake方式依赖第三方库注意事项
- 编写OpenCV程序时,需要注意的事项(持续更新)
- MSDB还原需要注意的事项及其配置
- flume的memeryChannel中transactionCapacity和sink的batchsize需要注意事项
- 网站运营:网站优化需要注意的事项
- 提高数据库性能,需要注意的某些事项
- OpenCV安装的注意事项
- HTML编写需要注意的事项
- 服务器日常维护需要注意事项
- ISA2004升级到ISA2006需要注意的事项
- 嵌入式软件工程师和需要与硬件交互的Android app开发工程师工作中注意事项
- 在J2ME下用KXML解析XML需要注意的事项
- 使用sql语句备份和恢复SQLserver数据库,以及需要注意的事项
- elasticsearch安装需要注意的事项
- 做好项目成本核算需要注意哪些事项