ROS2 twist sub linker errors
I am trying to build a node for a motor controller.
I have a timer, a pub<custom message>
and a sub to twist.
I have added both std_msgs
and geometry_msgs
to both the package.xml and the cmakelist.txt.
It compiles and links if I comment out the line below:
subscription_ = this->create_subscription<Twist>("cmd_vel", std::bind(&VescNode::twist_callback, this, _1),cmd_vel_qos_profile);
Then that line is added back in I get all sorts of linking errors.
Are std_msgs
and geometry_msgs
conflicting somehow?
Error:
CMakeFiles/vesc_node.dir/vesc_node.cpp.o: In function rclcpp::create_subscription_factory<geometry_msgs::msg::Twist_<std::allocator<void> >, std::_Bind<void (VescNode::*(VescNode*, std::_Placeholder<1>))(std::shared_ptr<geometry_msgs::msg::Twist_<std::allocator<void> > >)>, std::allocator<void>, geometry_msgs::msg::Twist_<std::allocator<void> >, rclcpp::Subscription<geometry_msgs::msg::Twist_<std::allocator<void> >, std::allocator<void> > >(std::_Bind<void (VescNode::*(VescNode*, std::_Placeholder<1>))(std::shared_ptr<geometry_msgs::msg::Twist_<std::allocator<void> > >)>&&, rclcpp::SubscriptionEventCallbacks const&, rclcpp::message_memory_strategy::MessageMemoryStrategy<geometry_msgs::msg::Twist_<std::allocator<void> >, std::allocator<void> >::SharedPtr, std::shared_ptr<std::allocator<void> >)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_subscription_options_t const&)#1}::operator()(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_subscription_options_t const&) const':
vesc_node.cpp:(.text._ZZN6rclcpp27create_subscription_factoryIN13geometry_msgs3msg6Twist_ISaIvEEESt5_BindIFM8VescNodeFvSt10shared_ptrIS5_EEPS7_St12_PlaceholderILi1EEEES4_S5_NS_12SubscriptionIS5_S4_EEEENS_19SubscriptionFactoryEOT0_RKNS_26SubscriptionEventCallbacksENS_23message_memory_strategy21MessageMemoryStrategyIT2_T1_E9SharedPtrES8_ISS_EENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK26rcl_subscription_options_tE_clESY_S16_S19_[_ZZN6rclcpp27create_subscription_factoryIN13geometry_msgs3msg6Twist_ISaIvEEESt5_BindIFM8VescNodeFvSt10shared_ptrIS5_EEPS7_St12_PlaceholderILi1EEEES4_S5_NS_12SubscriptionIS5_S4_EEEENS_19SubscriptionFactoryEOT0_RKNS_26SubscriptionEventCallbacksENS_23message_memory_strategy21MessageMemoryStrategyIT2_T1_E9SharedPtrES8_ISS_EENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK26rcl_subscription_options_tE_clESY_S16_S19_]+0x16d): undefined reference to rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<geometry_msgs::msg::Twist_<std::allocator<void> > >()'
collect2: error: ld returned 1 exit status
Code: vesc_node.cpp vesc_node.hpp
You can't expect us to be able to help you if you don't show those errors.
Add that information to your question text by editing it. Use the
edit
button/link.Also show your
CMakeLists.txt
(without all the boilerplate comments).Moreover, they have just
Twist
so unless they did a typedef / using call, then there's some problem. Moreover if they have multipleTwist
messages defined by different packages (which the words here make me suspect) then clearly there will be a conflict.I did implement the code with using
using geometry_msgs::msg::Twist;
I just tested it without that and I still get the linker error. Updated the question with more details and links to all the appropriate files.