如何通过CMake强制c ++编译器使用不同已安装软件包的版本之一? [英] How to force c++ compiler use one of different installed package's versions, using CMake?

查看:175
本文介绍了如何通过CMake强制c ++编译器使用不同已安装软件包的版本之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机上安装的ROS Fuerte使用opencv 2.2.我想使用刚安装的2.4.9版本.它的位置是/home/polar/soft/lib/opencv/opencv-2.4.9/build/lib.

ROS Fuerte I installed on my machine uses opencv 2.2. I would like to use 2.4.9 version just installed. Its location is /home/polar/soft/lib/opencv/opencv-2.4.9/build/lib.

请问如何使用CMake做到这一点? 通过我的搜索,看来find_library可以解决问题,但无法使其正常工作.

How to do that with CMake, please? From my search, it seems that find_library would solve the issue, but was not able to make it work.

=====我在这样的cpp代码中包含opencv

===== I include opencv in my cpp codes like this

  #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/opencv.hpp>
    #include "opencv2/imgproc/imgproc.hpp"

============这里是我的麦片

=========== HERE MY CMAKE

cmake_minimum_required(VERSION 2.8)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

rosbuild_genmsg()
rosbuild_gensrv()


# GSL
find_package( PkgConfig REQUIRED)
pkg_check_modules( gsl REQUIRED gsl )

SET(corners_opencv_flag ok)

#*******************************************************************
#*******************************************************************

#******                CORNERS OPENCV

#*******************************************************************
#*******************************************************************
if(corners_opencv_flag)

  #---
  SET(execFiles_corner_opencv
    corner_v1

    )

  #---
  foreach(file_ros ${execFiles_corner_opencv})
    rosbuild_add_executable(${file_ros} computer-vision/corners/${file_ros}.cpp ) 
  endforeach(file_ros)

  #---
endif(corners_opencv_flag)


#-------------------
# STACK 
#--------------------

SET(FILES_TO_RUN
  ${execFiles_corner_opencv} 
  )


#=======================================================
#
#     CUSTOM LIBRARIES
#
#
#=======================================================
PROJECT(VOLCANO)
SET(SRC ${VOLCANO_SOURCE_DIR}/src)


#******* boost
find_package( Boost REQUIRED COMPONENTS program_options regex )
include_directories( ${Boost_INCLUDE_DIRS} )

if(Boost_FOUND)
  message("\n\n Boost found \n\n")
endif()

find_package(OpenCV REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)


#===== Calculus
include_directories(${SRC}/calculus)
include_directories(${SRC}/calculus/matrix)
SET(MY_LIB
  ${MY_LIB}
 Calculus
 CholeskyDecompose
 )


#-------------------------------------------
# Linking the executables against the

#-------------------------------------------

foreach(file2link ${FILES_TO_RUN})

  target_link_libraries(${file2link} 
    ${MY_LIB} 
    ${MY_LIB} 
    ${gsl_LIBRARIES}
    ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
    ${OpenCV_LIB}
   )

endforeach(file2link)  


#--- sources folders
ADD_SUBDIRECTORY(src)

推荐答案

所以,我怀疑target_link_libraries(${file2link} .... ${OpenCV_LIB}) 是问题所在:OpenCV_LIB似乎已分配.

So, as I suspected, target_link_libraries(${file2link} .... ${OpenCV_LIB}) was the problem: OpenCV_LIB seems like allocated.

现在,我正在以这种方式链接opencv,并且可以正常工作:

Now, am linking opencv in this way and it works:

find_package(OpenCVV 2.4.9 PATHS /home/polar/soft/lib/opencv/opencv-2.4.9/cmake)
...
target_link_libraries(${file2link}  .... ${OpenCVV_LIB})

实际上我只是用了另一个名字,但OpenCV.

In fact I just used another name but OpenCV.

@texasflood,谢谢您的帮助.

@texasflood, thanks for your help.

这篇关于如何通过CMake强制c ++编译器使用不同已安装软件包的版本之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆