ubuntu下opencv2.4.10 和 opencv 3.10 多版本切换问题

1.由于需要,之前系统中是opencv2.4.10版本,后来安装opencv3.10版本,并支持多版本切换。通过以下命令可以查看opencv版本

pkg-config --modversion opencv


2.如果编译好并安装了opencv3.10版本,想切换到3.10版本,可以通过如下的方式,

通过修改bashrc文件来设置PKG_ CONFIG_PATH 和 LD_LIBRARY_PATH的路径来选择对应的opencv版本

sudo gedit ~/.bashrc

并在文件的默认追加新编译的3.10版本的路径,也就是cmake时:CMAKE_INSTALL_PREFIX=/usr/local/opencv/3.10

export PKG_CONFIG_PATH=/usr/local/opencv/3.10/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv/3.10/lib

然后执行命令,后面用pkg-config --modversion opencv 查看opencv版本的时候就是3.10版本

source ~/.bashrc
3.上面的这些过程并不能保证在写makefile中调用的是3.10版本的库,可能还是调用之前的2.4.10的库,具体还是要在CMakeList.txt中指定要找的opencv的目录,
opencv3.10的编译目录 /usr/local/opencv-3.1.0/build 下找到 OpenCVConfig.cmake 文件,并在CMakeList.txt中添加对应的路径信息。这样cmake的时候调用的就是3.10的库,想切换成原来的2.4.10版本只需将第二步的 bashrc文件和CMakeList.txt文件中修改的内容改成对应的opencv2.4.10的位置就好了。
# cmake needs this line
cmake_minimum_required(VERSION 2.8)
set (OpenCV_DIR "/usr/local/opencv-3.1.0/build")
# Define project name
project(myTest)
# 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}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()
# Declare the executable target built from your sources
add_executable(demo demo.cpp)
# Link your application with OpenCV libraries
target_link_libraries(demo ${OpenCV_LIBS})

参考网址:
http://www.cnblogs.com/xzd1575/p/5555523.html
http://stackoverflow.com/questions/18651178/cmake-error-at-cmakelists-txt-target-link-libraries
http://blog.csdn.net/cumt08113684/article/details/53006376#


你可能感兴趣的:(opencv,linux)