How to correctly link opencv3 under ROS Indigo?

asked 2016-06-01 00:25:56 -0500

polar gravatar image

updated 2016-06-01 01:26:25 -0500

Am getting this message error

../devel/lib/libirTest.so: undefined reference to `cv::ORB::create(int, float, int, int, int, int, int, int, int)'
../devel/lib/libirTest.so: undefined reference to `cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double)'

However am able to succefully compile outside ROS; that is, using the similar package without ROS.... Here is the CMake file am using

cmake_minimum_required(VERSION 2.8.3)
project(my_test_pkg)

SET(SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  rospy
  std_msgs
  message_generation
  genmsg
)
find_package(nodelet REQUIRED)

################################################
## Declare ROS messages, services and actions ##
################################################

 add_message_files(
   FILES
    velocity_trsl.msg 
   )

  generate_messages(
    DEPENDENCIES
    std_msgs
    )

catkin_package(
  CATKIN_DEPENDS message_generation cv_bridge image_transport roscpp rospy std_msgs
)

###########
## Build ##
###########
include_directories(
  ${catkin_INCLUDE_DIRS}
  )


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

#***********************
#******   Boost
#***********************

SET (BOOST_DIR "/home/polar/soft/lib/boost/boost_1_61_0")

FIND_PACKAGE(Boost 1.61.0 REQUIRED thread)
if (NOT Boost_FOUND)
  message(FATAL_ERROR " Fatal error: Boost (version >= 1.55) required.")
else()
  message(STATUS "Setting up BOOST")
  message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
  message(STATUS " Library  - ${Boost_LIBRARY_DIRS}")
  include_directories(${Boost_INCLUDE_DIRS})
  link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)   

#***********************
#******   OpenCV
#***********************
find_package( OpenCV 3.1.0 REQUIRED )
find_package( OpenCV 3.1.0 REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-3.1.0/cmake)
if (NOT OpenCV_FOUND)
  message(FATAL_ERROR "*****!!!!! opencv NOT found.")
endif (NOT OpenCV_FOUND)    

#****************************************
include_directories(${SRC}/calculus)
SET(MY_LIB
  irTest
  )

#   ALL EXEC FILES...
SET(EXE_TESTER  
   tester1
    )

  add_executable(tester1 ${CMAKE_CURRENT_SOURCE_DIR}/exe-main-files-stdl/testdir/tester1.cpp )

  SET(FILES_2_RUN
    ${EXE_TESTER}
    )


#--------------------------
foreach(file2link ${FILES_2_RUN})
  target_link_libraries(${file2link}
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
    ${gsl_LIBRARIES}
    ${OpenCV_LIBRARIES}
    ${OpenCV_LIBS}
    ${VISP_LIBRARIES}
    ${MY_LIB}
    )

  add_dependencies(${file2link} my_test_pkg_generate_messages_cpp)# newlly added for messages!!
endforeach(file2link)  

add_subdirectory(src)

Should it be a conflict between the opencv version am using and that (v2.4) used by ROS?

edit retag flag offensive close merge delete

Comments

Have you tried http://answers.ros.org/question/21404... That worked for me.

Thomas D gravatar image Thomas D  ( 2016-06-01 08:18:11 -0500 )edit

@Thomas D Yes, I tried but still the same issue.... Am trying to use opencv 2.4 but have other troubles....

polar gravatar image polar  ( 2016-06-01 21:52:25 -0500 )edit