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

[windows] Fix ambiguous call for tf2::convert on MSVC#462

Closed
tfoote wants to merge 1 commit intonoetic-develfrom
forward_port_444
Closed

[windows] Fix ambiguous call for tf2::convert on MSVC#462
tfoote wants to merge 1 commit intonoetic-develfrom
forward_port_444

Conversation

@tfoote
Copy link
Member

@tfoote tfoote commented May 13, 2020

  • rework ambiguous call on MSVC.

Forward port of #444 to noetic

@tfoote
Copy link
Member Author

tfoote commented May 13, 2020

@seanyen The patch from #444 doesn't forward port to noetic successfully. Could you take a look at why?

@gleichdick
Copy link

I don't want to be disrespectful, but I pointed out the problem at multiple places. Please correct me if I'm wrong.
The error message from the build is exactly the same as in #430:

11:56:08 test_convert.cpp:(.text._ZN3tf24impl9ConverterILb0ELb0EE7convertINS_10QuaternionEN5Eigen10QuaternionIdLi0EEEEEvRKT_RT0_[_ZN3tf24impl9ConverterILb0ELb0EE7convertINS_10QuaternionEN5Eigen10QuaternionIdLi0EEEEEvRKT_RT0_]+0x45): 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>&)'
11:56:08 collect2: error: ld returned 1 exit status

IMHO, the whole conversion stuff boils down to something like (taken from here)

#include <iostream>
namespace msgs {
    struct A_msg { 
        A_msg(){} // for clang
    };
}

namespace datatypes {
    struct B_dt {};
}

namespace tf2 {
    template <class A, class B>
    void fromMsg(const A&, B&);

    template <class A, class B>
    void convert(const A& a, B& b) {
        fromMsg(a, b);
    }

    //template<>
    void fromMsg(const msgs::A_msg& a, datatypes::B_dt& b) {}
}

int main () {
    const msgs::A_msg a;
    datatypes::B_dt b;
    tf2::convert(a, b);
    std::cout << "Hello, world!\n";
}

Compilation/linking fails with GCC, Clang and MSVC (with /permissive- flag set). If you uncomment the template<> statement or if you reorder the tf2 namespace

namespace tf2 {
    void fromMsg(const msgs::A_msg& a, datatypes::B_dt& b) {}

    template <class A, class B>
    void fromMsg(const A&, B&);

    template <class A, class B>
    void convert(const A& a, B& b) {
        fromMsg(a, b);
    }
}

it works fine.

When the conversion is requested, tf2::convert() uses the templated forward declaration for tf2::fromMsg() in tf2/transform_functions.h.
The point is that the corresponding function is not defined as a template specialization in tf2_eigen.h, but as a 'classic' overload. So, this correct overloaded function will only be chosen if it is defined before the generic forward declaration. Otherwise, these linking errors occur. The users have to take care on how they order their header #includes which is very error-prone.

@seanyen
Copy link
Contributor

seanyen commented Sep 10, 2020

@tfoote Sorry this is out of my radar. I will be checking this one soon.

@ahcorde ahcorde added the noetic label Feb 2, 2024
@sloretz
Copy link
Contributor

sloretz commented Apr 23, 2025

Thank you for the PR!

ROS Noetic will reach end-of-life on May 31st, 2025. Every change comes with a risk of introducing regressions, and there isn't much time left to fix them. To make sure this PR doesn't introduce any regressions please:

  • Describe how you tested this change
  • Recruit at least one more person to review this PR and try it out on their system

@sloretz
Copy link
Contributor

sloretz commented May 31, 2025

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.

@sloretz sloretz closed this May 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants