Cannot include tf2_geometry_msgs.h
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?
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?hello, had you solved this problem? I am currently facing the same issue.
I had to include the necessary files directly to
CMakeLists.txt
:I will try to find the real answer to this.
In ROS2 humble and potentially other distros, the header include has been changed to
tf2_geometry_msgs/tf2_geometry_msgs.hpp
.In my
/opt/ros/rolling/include/tf2_geometry_msgs/tf2_geometry_msgs
, I have both files:tf2_geometry_msgs.h
andtf2_geometry_msgs.hpp
. I believe this is for the backward/forward compatibility.