opencv使用cmake链接库函数出现usr/bin/ld: cannot find -lopencv_终极解决方案

由于安装了很多版本的opencv,希望通过cmake指定链接特定版本的opencv库。
由于我安装的opencv-3.1.0不是在系统默认的目录usr/lib中
CMakeLists.txt
如下

cmake_minimum_required(VERSION 2.8.3)
project(rosopencv)

ADD_EXECUTABLE(rosopencv rosopencv.cpp)
INCLUDE_DIRECTORIES(/home/topeet/programFiles/opencv-3.1.0/include)
INCLUDE_DIRECTORIES(/home/topeet/programFiles/opencv-3.1.0/include/opencv)
INCLUDE_DIRECTORIES(/home/topeet/programFiles/opencv-3.1.0/include/opencv2)
LINK_DIRECTORIES(/home/topeet/programFiles/opencv-3.1.0/lib)
SET(CMAKE_LIBRARY_PATH /home/topeet/programFiles/opencv-3.1.0/lib)
TARGET_LINK_LIBRARIES(rosopencv libopencv_calib3d.so libopencv_core.so libopencv_features2d.so libopencv_flann.so libopencv_highgui.so libopencv_imgcodecs.so libopencv_imgproc.so libopencv_ml.so libopencv_objdetect.so libopencv_photo.so libopencv_shape.so libopencv_videoio.so libopencv_video.so libopencv_videostab.so) 

编辑文件
vi /etc/ld.so.conf.d/libc.conf
在文件的末尾加入要调用的动态链接库的路径
/home/topeet/programFiles/opencv-3.1.0/lib
运行ldconfig

在控制台直接使用g++命令能够链接上
但是使用
cmake.
make

总是出现
/usr/bin/ld: cannot find -lopencv_calib3d
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_features2d

终极解决方案!!
直接将自定义安装的所有opencv动态链接库文件拷贝到use/lib文件夹下!!
再执行ldconfig

cmake.
make
就能成功了。

你可能感兴趣的:(图像处理)