Including Package "image_transport" in ROS2
I have a problem to include the package "image_transport" correctly. This is my CMakeList:
cmake_minimum_required(VERSION 3.5) project(camera_pkg)
Default to C++14
if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif()
find_package(ament_cmake REQUIRED COMPONENTS cv_bridge image_transport rclcpp sensor_msgs std_msgs )
find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(std_msgs REQUIRED) find_package(OpenCV REQUIRED) find_package(sensor_msgs REQUIRED) find_package(cv_bridge REQUIRED)
add_executable(camera camera_pkg.cpp) ament_target_dependencies(camera rclcpp std_msgs OpenCV cv_bridge)
install(TARGETS camera DESTINATION lib/${PROJECT_NAME} )
include_directories( ${OPENCV_INCLUDE_DIRS} ${ament_cmake_INCLUDE_DIRS} )
target_link_libraries(camera ${OPENCV_LIBRARIES})
target_link_libraries(camera ${OPENCV_LIBRARIES} ${ament_cmake_LIBRARIES})
target_link_libraries(camera ${rclcpp_LIBRARIES})
target_link_libraries(camera ${rclcpp_LIBRARIES} ${ament_cmake_LIBRARIES})
target_link_libraries(camera ${sensor_msgs_LIBRARIES})
target_link_libraries(camera ${sensor_msgs_LIBRARIES} ${ament_cmake_LIBRARIES})
target_link_libraries(camera PUBLIC ${EXTRA_LIBS})
if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() endif()
ament_package()
My package.xml looks like this:
<package format="2"> <name>camera_pkg</name> <version>0.13.0</version> <description>Examples of minimal publisher nodes</description> <maintainer <a="" href="mailto:email="sloretz@openrobotics.org">Shane">email="sloretz@openrobotics.org">Shane Loretz</maintainer> <maintainer <a="" href="mailto:email="aditya.pande@openrobotics.org">Aditya">email="aditya.pande@openrobotics.org"... Pande</maintainer> <license>Apache License 2.0</license> <author>Mikael Arguedas</author> <author>Morgan Quigley</author> <author <a="" href="mailto:email="jacob@openrobotics.org">Jacob">email="jacob@openrobotics.org">Jacob Perron</author></package>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rclcpp</build_depend> <build_depend>std_msgs</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>OpenCV2</build_depend> <build_depend>image_transport</build_depend> <build_depend>cv_bridge</build_depend>
<exec_depend>rclcpp</exec_depend> <exec_depend>std_msgs</exec_depend> <exec_depend>sensor_msgs</exec_depend> <exec_depend>OpenCV2</exec_depend> <exec_depend>image_transport</exec_depend> <exec_depend>cv_bridge</exec_depend>
<test_depend>ament_lint_auto</test_depend> <test_depend>ament_lint_common</test_depend>
<export> <build_type>ament_cmake</build_type> </export> </package>
When I compile my code with the "colcon build" command I get this error:
undefined reference to `image_transport::create_publisher(rclcpp::Node*, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, rmw_qos_profile_t)'
undefined reference to `image_transport::Publisher::publish(std::shared_ptr<sensor_msgs::msg::image_<std::allocator<void> > const> const&) const'
Can anyone help me what else needs to be added in the CMakeList and in the package.xml ?