ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
4

cv_bridge tutorial example not compiling in ROS Kinetic and Ubuntu 16.04

asked 2018-03-21 12:21:58 -0500

vik748 gravatar image

updated 2018-03-21 15:47:20 -0500

Hi, I am trying to run the full example in the cv_bridge tutorial at http://wiki.ros.org/cv_bridge/Tutoria... . I am having serious trouble compiling the node. I get the following undefined reference errors for opencv functions as follows:

CMakeFiles/c_test_node.dir/src/c_test_node.cpp.o: In function `ImageConverter::ImageConverter()':
c_test_node.cpp:(.text._ZN14ImageConverterC2Ev[_ZN14ImageConverterC5Ev]+0x3f1): undefined reference to `cv::namedWindow(cv::String const&, int)'
CMakeFiles/c_test_node.dir/src/c_test_node.cpp.o: In function `ImageConverter::imageCb(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
c_test_node.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1bd): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
c_test_node.cpp:(.text._ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN14ImageConverter7imageCbERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x1e2): undefined reference to `cv::waitKey(int)'
collect2: error: ld returned 1 exit status
c_test/CMakeFiles/c_test_node.dir/build.make:132: recipe for target '/home/auv/c_test_ws/devel/lib/c_test/c_test_node' failed
make[2]: *** [/home/auv/c_test_ws/devel/lib/c_test/c_test_node] Error 1
CMakeFiles/Makefile2:1813: recipe for target 'c_test/CMakeFiles/c_test_node.dir/all' failed
make[1]: *** [c_test/CMakeFiles/c_test_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

I have tried updating the include lines from:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

to

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

However, I am not having luck with that either.

Any help or insight on this is very appreciated.

As per @Maarten 's suggestion, I am including my CMakeLists.txt here:

cmake_minimum_required(VERSION 2.8.3)
project(c_test)
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
  tf
)
catkin_package(
CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(c_test_node src/c_test_node.cpp)
target_link_libraries(c_test_node ${OpenCV_LIBS} ${catkin_LIBRARIES})
edit retag flag offensive close merge delete

Comments

1

Pedantic (but important): it's actually compiling fine, it's during linking that you get errors. Changing the includes will not affect that.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-21 14:09:32 -0500 )edit

If you can't get it to work, please post your CMakeLists.txt too.

Maarten gravatar image Maarten  ( 2018-03-21 15:33:52 -0500 )edit

@Maarten thanks for the suggestion. Unfortunately adding the flag doesn't seemed to have helped. I will updated the question to add my CMakeLists.txt

vik748 gravatar image vik748  ( 2018-03-21 15:46:26 -0500 )edit
1

I also have

## OpenCV
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

in my CMakeLists.txt. I think the ${OpenCV_LIBS} variable is defined by this find_package script.

Maarten gravatar image Maarten  ( 2018-03-21 15:53:08 -0500 )edit

@Maarten I was doing find_package(OpenCV REQUIRED), but had commented it out. Now that in combination with target_link_libraries seems to have done the trick. Thanks very much for your help.

vik748 gravatar image vik748  ( 2018-03-21 15:55:48 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2018-03-21 15:33:26 -0500

My nodes using OpenCV have ${OpenCV_LIBS} in their target_link_libraries definition. I don't know what other OpenCV functions you are using, but since you get link errors on OpenCV symbols, it is worth checking whether you actually link the OpenCV library in your application.

edit flag offensive delete link more
5

answered 2018-03-21 15:57:24 -0500

vik748 gravatar image

As per @Maarten 's suggestion, updating the CMakeLists.txt as follows, seems to have solved the issue

cmake_minimum_required(VERSION 2.8.3)
project(c_test)
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
  tf
)
find_package(OpenCV REQUIRED)
catkin_package(
CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(c_test_node src/c_test_node.cpp)
target_link_libraries(c_test_node ${OpenCV_LIBS} ${catkin_LIBRARIES})
edit flag offensive delete link more

Comments

could you also post your package.xml file? I am having some trouble with the tutorial and it would help me see if I have made any mistakes in my package.xml Thank you

Jim Chaik gravatar image Jim Chaik  ( 2018-11-02 05:47:44 -0500 )edit
0

answered 2018-11-14 07:46:13 -0500

razerblade gravatar image

@Jim Chalik

could you also post your package.xml file? I am having some trouble with the tutorial and it would help me see if I have made any mistakes in my package.xml Thank you

package.xml would look something like this:

<?xml version="1.0"?>
<package format="2">
  <name>c_test</name>
  <version>0.0.0</version>
  <description>The c_test package</description>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>cv_bridge</build_depend>
  <build_depend>image_transport</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_export_depend>cv_bridge</build_export_depend>
  <build_export_depend>image_transport</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <exec_depend>cv_bridge</exec_depend>
  <exec_depend>image_transport</exec_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>std_msgs</exec_depend>
</package>
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-21 12:21:58 -0500

Seen: 4,169 times

Last updated: Nov 14 '18