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

[ROS2] tf2::fromMsg linker error

asked 2020-09-18 05:17:47 -0500

Myzhar gravatar image

Hi all, I'm getting a weird linker error using tf2::fromMsg function in ROS2 Eloquent.

tf2::Transform mSensor2BaseTransf;
[...]

// Save the transformation
geometry_msgs::msg::TransformStamped s2b =
        mTfBuffer->lookupTransform(mDepthFrameId, mBaseFrameId, rclcpp::Time(0), rclcpp::Duration(0.1));
// Get the TF2 transformation
tf2::fromMsg(s2b.transform, mSensor2BaseTransf);

This code is used inside a Component library that compiles without any problem, but when I create a C++ Container that load the component I get the following error:

undefined reference to `void tf2::fromMsg<geometry_msgs::msg::Transform_<std::allocator<void> >, tf2::Transform>(geometry_msgs::msg::Transform_<std::allocator<void> > const&, tf2::Transform&)'

Any idea about how to solve the problem?

Thank you Walter collect2: error: ld returned 1 exit status

edit retag flag offensive close merge delete

Comments

Same issue in Humble. (I'm trying to use tf2::fromMsg on a TwistStamped to populate a 6D Eigen vector)

undefined symbol: void tf2::fromMsg<std::shared_ptr<geometry_msgs::msg::TwistStamped_<std::allocator<void> > const>, Eigen::Matrix<double, 6, 1, 0, 6, 1> >(std::shared_ptr<geometry_msgs::msg::TwistStamped_<std::allocator<void> > const> const&, Eigen::Matrix<double, 6, 1, 0, 6, 1>&)

danzimmerman gravatar image danzimmerman  ( 2022-09-12 18:51:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-09-12 21:24:25 -0500

tfoote gravatar image

Do you have the appropriate header from tf2_geometry_msgs included for your datatype? It's a templated function so if you use it you're expected to include the necessary headers for your datatype. In this case it looks like you need https://github.com/ros2/geometry2/blo...

The other usage is likely getting lucky that something else is including that header before your code execution so it will compile. But in your reduced set you don't get lucky relying on the transitive include.

edit flag offensive delete link more

Comments

Do you have the appropriate header from tf2_geometry_msgs included for your datatype?

In my case I was getting too tired to properly read C++ error messages to and notice that I was trying to convert a std::shared_ptr<TwistStamped> directly to an Eigen::Vector<double, 6>, so there obviously wasn't an appropriate specialization in tf2_eigen.h๐Ÿ˜…

Operating on the underlying Twist works fine.

danzimmerman gravatar image danzimmerman  ( 2022-09-13 16:48:59 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-09-18 05:17:47 -0500

Seen: 805 times

Last updated: Sep 12 '22