Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force c++ compiler use one of different installed package's versions, using CMake?

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.

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.

===== 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)
like image 241
Courier Avatar asked Feb 13 '15 19:02

Courier


2 Answers

Add this to your CMakeLists.txt replacing the previous find_package(OpenCV) line:

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

There should be a cmake directory in your opencv installation.

like image 164
texasflood Avatar answered Sep 19 '22 11:09

texasflood


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

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

In fact I just used another name but OpenCV.

@texasflood, thanks for your help.

like image 44
Courier Avatar answered Sep 22 '22 11:09

Courier