Ask Your Question
0

Groovy and OpenCV: Linker errors

asked 2013-02-19 22:21:24 -0600

dinsn gravatar image

Hi! I'm trying to compile a ROS package in Ubuntu 12.04 64bit which has been used in Fuerte and uses OpenCV. As recommended on the opencv2 ROS Wiki page (http://www.ros.org/wiki/opencv2), I would like to change the way of including OpenCV from the old <depend package="opencv2" /> tag in the manifest.xml. Thus according to the wiki, I changed that entry to <rosdep name="opencv2"/> and edited my CMakeLists.txt to contain

find_package(OpenCV REQUIRED)
#define some target ...
target_link_libraries(my_target ${OpenCV_LIBRARIES})

If I try to build the package with rosmake I get errors during the linking process:

Linking CXX executable ../bin/mr
  ../lib/libmr_lib.so: undefined reference to `cv::waitKey(int)'
  ../lib/libmr_lib.so: undefined reference to `cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
  ../lib/libmr_lib.so: undefined reference to `cvMoveWindow'
  ../lib/libmr_lib.so: undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
  collect2: ld returned 1 exit status
  make[3]: *** [../bin/mr] Error 1

libopencv2.4-dev is installed. Any help would be very appreciated! Thank you!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-02-20 19:31:46 -0600

dinsn gravatar image

Thanks a lot for the answer! I've found out that I had an error in my CMakeLists. Not really used to the CMake building procedure... I'm building two libraries and one executable to which the libraries are linked. One of the libs uses OpenCV and I only used one target_link_libraries command to link everything instead of first linking OpenCV to the lib with one command and then linking the lib to the executable with another. So instead of

target_link_libraries(my_exec my_lib ${OpenCV_LIBS})

I'm now calling

target_link_libraries(my_lib ${OpenCV_LIBS})
target_link_libraries(my_exec my_lib)

and it works...

edit flag offensive delete link more
0

answered 2013-02-20 08:14:23 -0600

kalectro gravatar image

updated 2013-02-20 08:17:23 -0600

What I did when using opencv was find_package cv_bridge, let catkin depend on it and link against the catkin libraries. It works for me, feel free to down vote this answer if it is not nice ;)

find_package(catkin REQUIRED COMPONENTS cv_bridge roscpp)
catkin_package(
   CATKIN_DEPENDS cv_bridge roscpp
   DEPENDS system_lib
)
target_link_libraries(my_node ${catkin_LIBRARIES})

Since many libraries will become system dependencies in the long run, this should still work later. In fact I also tried it on a platform where OpenCV was installed outside of ROS and it works

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-02-19 22:21:24 -0600

Seen: 1,252 times

Last updated: Feb 20 '13