小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
-
完全复制4.2.2教程上的代码至wang2.cpp,colcon build后只有village_wang报错(粘贴3.5中的基础内容不报错),错误内容如下:
Starting >>> village_li Starting >>> village_wang Finished <<< village_li [1.83s] --- stderr: village_wang CMakeFiles/wang2_node.dir/src/wang2.cpp.o: In function `rclcpp::create_subscription_factory<std_msgs::msg::String_<std::allocator<void> >, std::_Bind<void (SingleDogNode::*(SingleDogNode*, std::_Placeholder<1>))(std::shared_ptr<std_msgs::msg::String_<std::allocator<void> > >)>, std::allocator<void>, std_msgs::msg::String_<std::allocator<void> >, rclcpp::Subscription<std_msgs::msg::String_<std::allocator<void> >, std::allocator<void> > >(std::_Bind<void (SingleDogNode::*(SingleDogNode*, std::_Placeholder<1>))(std::shared_ptr<std_msgs::msg::String_<std::allocator<void> > >)>&&, rclcpp::SubscriptionEventCallbacks const&, rclcpp::message_memory_strategy::MessageMemoryStrategy<std_msgs::msg::String_<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': wang2.cpp:(.text._ZZN6rclcpp27create_subscription_factoryIN8std_msgs3msg7String_ISaIvEEESt5_BindIFM13SingleDogNodeFvSt10shared_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_factoryIN8std_msgs3msg7String_ISaIvEEESt5_BindIFM13SingleDogNodeFvSt10shared_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<std_msgs::msg::String_<std::allocator<void> > >()' CMakeFiles/wang2_node.dir/src/wang2.cpp.o: In function `rclcpp::Publisher<std_msgs::msg::UInt32_<std::allocator<void> >, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_publisher_options_t const&, rclcpp::PublisherEventCallbacks const&, std::shared_ptr<std::allocator<std_msgs::msg::UInt32_<std::allocator<void> > > > const&)': wang2.cpp:(.text._ZN6rclcpp9PublisherIN8std_msgs3msg7UInt32_ISaIvEEES4_EC2EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKNS_23PublisherEventCallbacksERKSt10shared_ptrISaIS5_EE[_ZN6rclcpp9PublisherIN8std_msgs3msg7UInt32_ISaIvEEES4_EC5EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERK23rcl_publisher_options_tRKNS_23PublisherEventCallbacksERKSt10shared_ptrISaIS5_EE]+0x26): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::UInt32_<std::allocator<void> > >()' collect2: error: ld returned 1 exit status make[2]: *** [wang2_node] Error 1 make[1]: *** [CMakeFiles/wang2_node.dir/all] Error 2 make: *** [all] Error 2 --- Failed <<< village_wang [5.55s, exited with code 2] Summary: 1 package finished [5.73s] 1 package failed: village_wang 1 package had stderr output: village_wang
-
@小鱼 确实是依赖的问题,最后是在village_wang下的CMakeLists.txt中,加上了std_msgs的依赖,问题解决,谢谢小鱼老师
ament_target_dependencies(wang2_node rclcpp std_msgs)
-
收到话题数据的回调函数,函数体反括号是多了一个分号吧
-
@1634600186 改下格式呀兄弟,这个太难看了
-
@小鱼 稍微排版了一下,实在是报错的内容太杂乱了,最后面的这一句貌似有提示,抱歉了
undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::UInt32_<std::allocator<void> > >()'
-
@1634600186 可以使用代码块,我们的编辑器是支持markdown的
-
@1634600186 在 动手学ROS2 4.2.2报错 中说:
undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<std_msgs::msg::UInt32_<std::allocator<void> > >()'
看一下你的cmakelists,有没有添加依赖
-
@小鱼 确实是依赖的问题,最后是在village_wang下的CMakeLists.txt中,加上了std_msgs的依赖,问题解决,谢谢小鱼老师
ament_target_dependencies(wang2_node rclcpp std_msgs)
-
-
@1634600186 为什么我添加了之后报如下错误!
Starting >>> village_li Starting >>> village_wang --- stderr: village_wang CMake Error at /opt/ros/eloquent/share/ament_cmake_target_dependencies/cmake/ament_target_dependencies.cmake:62 (message): ament_target_dependencies() the passed package name 'std_msgs' was not found before Call Stack (most recent call first): CMakeLists.txt:36 (ament_target_dependencies) make: *** [cmake_check_build_system] Error 1 --- Failed <<< village_wang [0.58s, exited with code 2] Aborted <<< village_li [0.81s] Summary: 0 packages finished [0.96s] 1 package failed: village_wang 1 package aborted: village_li 1 package had stderr output: village_wang
-
@505106035 前面还有一句
find_package(std_msgs REQUIRE)
-