ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Kinetic: cv_bridge unresolved reference to toImageMsg()

asked 2018-06-06 04:08:45 -0500

nullptr gravatar image

Hello guys,

I have been struggling with adding cv_brige to my custom ROS package called camera_pkg.

When I try to compile this particular package with catkin_make --only-pkg-with-deps camera_pkg that is the output I receive:

[ 94%] Linking CXX executable /home/ros/catkin_ws/devel/lib/camera_pkg/camera_node
/home/ros/catkin_ws/devel/lib/libcamera_pkg.so: undefined reference to `cv_bridge::CvImage::toImageMsg() const'
collect2: error: ld returned 1 exit status
camera_pkg/CMakeFiles/camera_node.dir/build.make:184: recipe for target '/home/ros/catkin_ws/devel/lib/camera_pkg/camera_node' failed
make[2]: *** [/home/ros/catkin_ws/devel/lib/camera_pkg/camera_node] Error 1
CMakeFiles/Makefile2:1018: recipe for target 'camera_pkg/CMakeFiles/camera_node.dir/all' failed
make[1]: *** [camera_pkg/CMakeFiles/camera_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

There is a part of the code that is using cv_bridge package:

if (false == get_dummy_camera_ptr())
{
    ROS_ERROR("Cannot reach camera - pointer to its instance is nullptr");
    return false;
}

auto frame = get_dummy_camera_ref().get_frame();

sensor_msgs::ImagePtr im_msg = cv_bridge::CvImage(std_msgs::Header(), "rgb8", frame.m_data).toImageMsg();
response.image = *im_msg;

ROS_INFO("I have frame!");

return true;

package.xml looks like below:

<?xml version="1.0"?>
<package format="2">
  <name>camera_pkg</name>
  <version>0.0.0</version>
  <description>The camera_pkg package</description>

  <maintainer email="x@x.x">X</maintainer>

  <!-- One license tag required, multiple allowed, one license per tag -->
  <license>TODO</license>

  <url type="website">x</url>

  <author email="x@x.x">X</author>

  <buildtool_depend>catkin</buildtool_depend>

  <depend>roscpp</depend>
  <depend>cv_bridge</depend>

  <build_depend>core_pkg</build_depend>
  <build_depend>message_generation</build_depend>

  <exec_depend>message_runtime</exec_depend>

  <export></export>
</package>

When CMakeLists.txt is as below:

cmake_minimum_required(VERSION 2.8.3)
project(camera_pkg)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  cv_bridge
  sensor_msgs
  message_generation
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)

## Custom packages
find_package(core_pkg REQUIRED)

## 3rd parties packages
find_package(Boost REQUIRED COMPONENTS
  program_options)

find_package(OpenCV)

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

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-06 06:15:12 -0500

nullptr gravatar image

updated 2018-06-06 06:16:04 -0500

I found the solution for my problem.

There was a problem with CMakeLists.txt.

Basically, I create shared library:

add_library(${PROJECT_NAME}
  src/camera/dummy_camera.cpp
  src/handler/camera_service.cpp
  src/handler/camera_info_topic_publisher.cpp
  src/manager/camera_node_manager.cpp
)

That library has 3rd parties dependencies such as OpenCV. I did not link this shared library's target against all depended libraries.

I added that part to CMakeLists.txt and it started to build and link without any error:

target_link_libraries(${PROJECT_NAME}
  ${catkin_LIBRARIES}
  ${Boost_LIBRARIES}
  ${OpenCV_LIBRARIES}
)

I cannot mark my reply as an answer, but it should be treated as an answer for this topic's question.

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

2 followers

Stats

Asked: 2018-06-06 04:07:49 -0500

Seen: 505 times

Last updated: Jun 06 '18