Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.
This repository was archived by the owner on May 31, 2025. It is now read-only.

missing symbol on convert(tf2::Quaternion, Eigen::Quaternion) #430

Closed

Description

@gleichdick

I build moveit and geometry2 from source, importing moveit_commander python module throws an ImportError due to missing symbol. See moveit/moveit1#1785. Reverting #367 fixes the issue.

With HEAD pointed to cd55e45, following snippet (extracted from here) builds fine:

#include <tf2/LinearMath/Quaternion.h>
#include <Eigen/Geometry>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <tf2_eigen/tf2_eigen.h>
#include <iostream>

int main() {
  Eigen::Quaterniond eq;
  const tf2::Quaternion tq(0,1,0,1);

  tf2::convert(tq, eq);
  std::cout << eq.toRotationMatrix() << '\n';
}

With current melodic-devel (#367 applied, 1cbda1e), the symbol is also missing:

$ g++ -I/usr/include/eigen3/ -I/ws_moveit/install/include/ -I/opt/ros/melodic/include/ test.cpp 
/tmp/ccQipwpW.o: In function `void tf2::impl::Converter<false, false>::convert<tf2::Quaternion, Eigen::Quaternion<double, 0> >(tf2::Quaternion const&, Eigen::Quaternion<double, 0>&)':
test.cpp:(.text._ZN3tf24impl9ConverterILb0ELb0EE7convertINS_10QuaternionEN5Eigen10QuaternionIdLi0EEEEEvRKT_RT0_[_ZN3tf24impl9ConverterILb0ELb0EE7convertINS_10QuaternionEN5Eigen10QuaternionIdLi0EEEEEvRKT_RT0_]+0x41): undefined reference to `void tf2::fromMsg<geometry_msgs::Quaternion_<std::allocator<void> >, Eigen::Quaternion<double, 0> >(geometry_msgs::Quaternion_<std::allocator<void> > const&, Eigen::Quaternion<double, 0>&)'
collect2: error: ld returned 1 exit status

The function is declared in tf2_geometry_msgs.h as inline, but not template<>. If I got it right, the declaration order is:

  • template<class A, class B> fromMsg(const A&, B&);
  • template<class A, class B> void convert(const A&, B&) {...}
  • inline void fromMsg(const geometry_msgs::Quaternion &, tf2::Quaternion&) {...}

So, in impl::convert the correct overload is not found because it is defined as a stand-alone function afterwards (I guess).

When template<> is added to the fromMsg overloads, the snippet compiles.

Activity

  1. rhaschke commented on Nov 28, 2019

    @rhaschke
    Contributor

    Hint: If you can provide a PR (and I believe you can based on your analysis of the issue), the issue has higher chances to be fixed soon.

  2. gleichdick commented on Nov 28, 2019

    @gleichdick
    Author

    Well, this whole template stuff isn't that easy. I tried adding template<> on each fromMsg() and toMsg() overload (in general the bug also applies to toMsg), but that does not work because one template parameter is the return value toMsg (return values are not taken into account for template parameter deduction). GCC complains:

       out.orientation = toMsg(in.getRotation());
                                               ^
    In file included from /ws_moveit/install/include/tf2/convert.h:35:0,
                     from /ws_moveit/install/include/tf2_geometry_msgs/tf2_geometry_msgs.h:35,
                     from test.cpp:3:
    /ws_moveit/install/include/tf2/transform_functions.h:90:5: note: candidate: template<class A, class B> B tf2::toMsg(const A&)
       B toMsg(const A& a);
         ^~~~~
    /ws_moveit/install/include/tf2/transform_functions.h:90:5: note:   template argument deduction/substitution failed:
    In file included from test.cpp:3:0:
    /ws_moveit/install/include/tf2_geometry_msgs/tf2_geometry_msgs.h:427:43: note:   couldn't deduce template parameter ‘B’
       out.orientation = toMsg(in.getRotation());
                                               ^
    

    possible solutions:

    • rearrange header includes in tf2_geometry_msgs.h
    • add forward declarations before includes in tf2_geometry_msgs.h
    • template wrappers introduced in Apply 202 and 223 together #254 like
      template <>
      inline
      ROS_DEPRECATED geometry_msgs::QuaternionStamped toMsg(const tf2::Stamped<tf2::Quaternion>& in);
      //Backwards compatibility remove when forked for Lunar or newer
      template <>
      inline
      geometry_msgs::QuaternionStamped toMsg(const tf2::Stamped<tf2::Quaternion>& in)
      {
      return toMsg(in);
      }
    • template<> everything

    1 and 2 still rely on the correct order of header includes (tf2_geometry_msgs.h before tf2/convert.h), so these options aren't bullet proof.
    Number 3 clutters up the headers but keeps backward compatibility and does not rely on the include order.
    Number 4 breaks everything, as toMsg has to be specified manually on each call. Maybe in the next release, the signature could be changed so that every parameter could be deducted.

  3. gleichdick commented on Feb 10, 2020

    @gleichdick
    Author

    #433 is ready for a review, downstream projects have to update their A tf2::toMsg(const B&) calls to either A& tf2::toMsg(const B&, A&) or tf2::convert(const B&, A&). The latter one is backwards compatible (except for three-way conversions).
    @rhaschke moveit melodic-devel compiles with these changes (with moveit_visual_tools updated as well). Should I open a PR for it to make a review easier?

  4. sloretz commented on May 31, 2025

    @sloretz
    Contributor

    ROS 1 is end-of-life (EOL) as of today, May 31st 2025. I am archiving this repository because:

    • it only supports ROS 1
    • it isn't needed anymore in ROS 2

    If you still rely on ROS 1, read this page to learn about your options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions