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

Cannot include tf2_geometry_msgs.h

asked 2020-02-18 12:06:31 -0600

mdeegan gravatar image

I am trying to include tf2_geometry_msgs/tf2_geometry_msgs.h, however I keep getting the following include error:

In file included from /home/martin/ros2_ws/src/acrobat_packages/acrobat_common/tests/lie_group_conversions_test.cpp:3:0:
/home/martin/ros2_ws/src/acrobat_packages/acrobat_common/include/acrobat_common/lie_groups/lie_group_conversions.hpp:3:10: fatal error: tf2_geometry_msgs/tf2_geometry_msgs.h: No such file or directory
 #include <tf2_geometry_msgs/tf2_geometry_msgs.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is my CMakeLists.txt:

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3)
find_package(Sophus REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)

include_directories(include)

add_library(${PROJECT_NAME} SHARED 

  # Lie groups
  src/lie_groups/lie_groups.cpp
  src/lie_groups/lie_group_conversions.cpp

)
target_include_directories(${PROJECT_NAME}
  PUBLIC
  "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
  "$<INSTALL_INTERFACE:include>"
)
set(AMENT_DEPENDENCIES 
  "Eigen3" 
  "Sophus" 
  "tf2" 
  "tf2_ros"
  "geometry_msgs"
  "tf2_geometry_msgs"
)

ament_target_dependencies(${PROJECT_NAME} ${AMENT_DEPENDENCIES})

And my package.xml

  <build_depend>eigen3_cmake_module</build_depend>
  <build_depend>Eigen3</build_depend>
  <build_depend>Sophus</build_depend>

  <depend>geometry_msgs</depend>
  <depend>tf2</depend>
  <depend>tf2_ros</depend>
  <depend>tf2_geometry_msgs</depend>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  <test_depend>ament_cmake_gtest</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>

I cannot see what I am doing wrong here. Does ament_target_dependencies not set target include directories?

edit retag flag offensive close merge delete

Comments

The error is originating from lie_group_conversions_test.cpp. Can you show the CMake for how that file is included in a target and built?

jdlangs gravatar image jdlangs  ( 2020-10-14 09:39:27 -0600 )edit

hello, had you solved this problem? I am currently facing the same issue.

enyuin gravatar image enyuin  ( 2022-01-03 09:28:30 -0600 )edit

I had to include the necessary files directly to CMakeLists.txt:

include_directories(/opt/ros/rolling/include/tf2_geometry_msgs)
include_directories(/opt/ros/rolling/include/tf2)
include_directories(/opt/ros/rolling/include/tf2_ros)

I will try to find the real answer to this.

hubacji1 gravatar image hubacji1  ( 2022-06-03 08:36:24 -0600 )edit
1

In ROS2 humble and potentially other distros, the header include has been changed to tf2_geometry_msgs/tf2_geometry_msgs.hpp.

swiz23 gravatar image swiz23  ( 2022-08-02 21:47:42 -0600 )edit

In my /opt/ros/rolling/include/tf2_geometry_msgs/tf2_geometry_msgs, I have both files: tf2_geometry_msgs.h and tf2_geometry_msgs.hpp. I believe this is for the backward/forward compatibility.

hubacji1 gravatar image hubacji1  ( 2022-08-03 09:43:44 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
-1

answered 2020-10-14 03:44:14 -0600

wiyogo gravatar image

updated 2020-10-16 03:16:05 -0600

sudo apt install ros-melodic-tf2-geometry-msgs works in my workspace.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2020-02-18 12:06:31 -0600

Seen: 7,036 times

Last updated: Oct 16 '20