0
$\begingroup$

Rosanswers logo

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:


camera_pkg 0.13.0 Examples of minimal publisher nodes Shane Loretz Aditya Pande Apache License 2.0 Mikael Arguedas Morgan Quigley Jacob Perron

<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>

ament_cmake

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, std::allocator > 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 ?


Originally posted by SJeya on ROS Answers with karma: 1 on 2022-01-24

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You'll need to add a

find_package(image_transport REQUIRED)

and add a

ament_target_dependencies(camera
    rclcpp
    sensor_msgs
    image_transport)

Note that it's recommended to use the ament_target_dependencies(...) for ros2 packages vs using target_link_libraries(...)


Originally posted by ChuiV with karma: 1046 on 2022-02-04

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by SJeya on 2022-02-05:
I have added these lines. But I get a different error now:

CMake Error at CMakeLists.txt:28 (find_package): By not providing "Findimage_transport.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "image_transport", but CMake did not find one.

Could not find a package configuration file provided by "image_transport" with any of the following names:

image_transportConfig.cmake
image_transport-config.cmake

Add the installation prefix of "image_transport" to CMAKE_PREFIX_PATH or set "image_transport_DIR" to a directory containing one of the above files. If "image_transport" provides a separate development package or SDK, be sure it has been installed.

Do you know where the problem could be ?

Comment by ChuiV on 2022-02-05:
Is the image transport package installed?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.