CMakeLists.txt添加opencv库注意事项

https://blog.csdn.net/u012816621/article/details/51732932

# 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})

【注意事项】
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的位置去变化。

解压到sln一级目录项目属性 C/C++ 附加包含目录 填写Libs/x86/opencv_v3.4.0/include路径 属性中链接器,所有选项附加目录填写Libs/x86/opencv_v3.4.0/lib 附加依赖项: opencv_aruco340.lib;f.lib;opencv_bgsegm340.lib;opencv_bgsegm340d.lib;opencv_bioinspired340.lib;opencv_bioinspired340d.lib;opencv_calib3d340.lib;opencv_calib3d340d.lib;opencv_ccalib340.lib;opencv_ccalib340d.lib;opencv_core340.lib;opencv_core340d.lib;opencv_datasets340.lib;opencv_datasets340d.lib;opencv_dnn340.lib;opencv_dnn340d.lib;opencv_dpm340.lib;opencv_dpm340d.lib;opencv_face340.lib;opencv_face340d.lib;opencv_features2d340.lib;opencv_features2d340d.lib;opencv_flann340.lib;opencv_flann340d.lib;opencv_fuzzy340.lib;opencv_fuzzy340d.lib;opencv_highgui340.lib;opencv_highgui340d.lib;opencv_imgcodecs340.lib;opencv_imgcodecs340d.lib;opencv_imgproc340.lib;opencv_imgproc340d.lib;opencv_img_hash340.lib;opencv_img_hash340d.lib;opencv_line_descriptor340.lib;opencv_line_descriptor340d.lib;opencv_ml340.lib;opencv_ml340d.lib;opencv_objdetect340.lib;opencv_objdetect340d.lib;opencv_optflow340.lib;opencv_optflow340d.lib;opencv_phase_unwrapping340.lib;opencv_phase_unwrapping340d.lib;opencv_photo340.lib;opencv_photo340d.lib;opencv_plot340.lib;opencv_plot340d.lib;opencv_reg340.lib;opencv_reg340d.lib;opencv_rgbd340.lib;opencv_rgbd340d.lib;opencv_saliency340.lib;opencv_saliency340d.lib;opencv_shape340.lib;opencv_shape340d.lib;opencv_stereo340.lib;opencv_stereo340d.lib;opencv_stitching340.lib;opencv_stitching340d.lib;opencv_structured_light340.lib;opencv_structured_light340d.lib;opencv_superres340.lib;opencv_superres340d.lib;opencv_surface_matching340.lib;opencv_surface_matching340d.lib;opencv_text340.lib;opencv_text340d.lib;opencv_tracking340.lib;opencv_tracking340d.lib;opencv_video340.lib;opencv_video340d.lib;opencv_videoio340.lib;opencv_videoio340d.lib;opencv_videostab340.lib;opencv_videostab340d.lib;opencv_xfeatures2d340.lib;opencv_xfeatures2d340d.lib;opencv_ximgproc340.lib;opencv_ximgproc340d.lib;opencv_xobjdetect340.lib;opencv_xobjdetect340d.lib;opencv_xphoto340.lib;opencv_xphoto340d.lib;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值