[无人车] ros2 下 build 报错:collect2: error: ld returned 1 exit status

编译报错

root@ubuntu:~/dev_ws# colcon build --packages-select line_follower_perception
Starting >>> line_follower_perception
[Processing: line_follower_perception]
[Processing: line_follower_perception]
--- stderr: line_follower_perception
/usr/bin/ld: CMakeFiles/line_follower_perception.dir/src/line_follower_perception.cpp.o: in function `rclcpp::create_subscription_factory<nav_msgs::msg::Odometry_<std::allocator<void> >, std::_Bind<void (LineFollowerPerceptionNode::*(LineFollowerPerceptionNode*, std::_Placeholder<1>))(std::shared_ptr<nav_msgs::msg::Odometry_<std::allocator<void> > >)>, std::allocator<void>, nav_msgs::msg::Odometry_<std::allocator<void> >, rclcpp::Subscription<nav_msgs::msg::Odometry_<std::allocator<void> >, std::allocator<void>, rclcpp::message_memory_strategy::MessageMemoryStrategy<nav_msgs::msg::Odometry_<std::allocator<void> >, std::allocator<void> > >, rclcpp::message_memory_strategy::MessageMemoryStrategy<nav_msgs::msg::Odometry_<std::allocator<void> >, std::allocator<void> > >(std::_Bind<void (LineFollowerPerceptionNode::*(LineFollowerPerceptionNode*, std::_Placeholder<1>))(std::shared_ptr<nav_msgs::msg::Odometry_<std::allocator<void> > >)>&&, rclcpp::SubscriptionOptionsWithAllocator<std::allocator<void> > const&, rclcpp::message_memory_strategy::MessageMemoryStrategy<nav_msgs::msg::Odometry_<std::allocator<void> >, std::allocator<void> >::SharedPtr, std::shared_ptr<rclcpp::topic_statistics::SubscriptionTopicStatistics<nav_msgs::msg::Odometry_<std::allocator<void> > > >)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}::operator()(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) const':
line_follower_perception.cpp:(.text._ZZN6rclcpp27create_subscription_factoryIN8nav_msgs3msg9Odometry_ISaIvEEESt5_BindIFM26LineFollowerPerceptionNodeFvSt10shared_ptrIS5_EEPS7_St12_PlaceholderILi1EEEES4_S5_NS_12SubscriptionIS5_S4_NS_23message_memory_strategy21MessageMemoryStrategyIS5_S4_EEEESK_EENS_19SubscriptionFactoryEOT0_RKNS_32SubscriptionOptionsWithAllocatorIT1_EENT4_9SharedPtrES8_INS_16topic_statistics27SubscriptionTopicStatisticsIT2_EEEENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3QoSEE_clES13_S1B_S1E_[_ZZN6rclcpp27create_subscription_factoryIN8nav_msgs3msg9Odometry_ISaIvEEESt5_BindIFM26LineFollowerPerceptionNodeFvSt10shared_ptrIS5_EEPS7_St12_PlaceholderILi1EEEES4_S5_NS_12SubscriptionIS5_S4_NS_23message_memory_strategy21MessageMemoryStrategyIS5_S4_EEEESK_EENS_19SubscriptionFactoryEOT0_RKNS_32SubscriptionOptionsWithAllocatorIT1_EENT4_9SharedPtrES8_INS_16topic_statistics27SubscriptionTopicStatisticsIT2_EEEENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3QoSEE_clES13_S1B_S1E_]+0x34): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<nav_msgs::msg::Odometry_<std::allocator<void> > >()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/line_follower_perception.dir/build.make:137: line_follower_perception] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/line_follower_perception.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< line_follower_perception [1min 16s, exited with code 2]

其中,

collect2: error: ld returned 1 exit status

问题出在添加了以下代码:

  subscriber_odom_info_ = this->create_subscription<nav_msgs::msg::Odometry>(
      "/odom", 10, std::bind(&LineFollowerPerceptionNode::subscription_odom_info_callback, this, std::placeholders::_1));

链接的时候找不到 nav_msgs 的lib,解决方法是在工程文件夹的 CMakeLists.txt 中添加以下代码:

find_package(nav_msgs REQUIRED)
find_package(tf2 REQUIRED)


ament_target_dependencies(
  ${PROJECT_NAME}

  ...

  nav_msgs
  tf2
)
相关推荐
静心问道1 小时前
WGAN算法
深度学习·算法·机器学习
清纯世纪3 小时前
基于深度学习的图像分类或识别系统(含全套项目+PyQt5界面)
开发语言·python·深度学习
AIPaPerPass写论文3 小时前
写论文去哪个网站?2024最佳五款AI毕业论文学术网站
人工智能·深度学习·chatgpt·powerpoint·ai写作
5pace4 小时前
PyTorch深度学习快速入门教程【土堆】基础知识篇
人工智能·pytorch·深度学习
AI完全体6 小时前
AI小项目4-用Pytorch从头实现Transformer(详细注解)
人工智能·pytorch·深度学习·机器学习·语言模型·transformer·注意力机制
AI知识分享官6 小时前
智能绘画Midjourney AIGC在设计领域中的应用
人工智能·深度学习·语言模型·chatgpt·aigc·midjourney·llama
天南星7 小时前
PaddleOCR和PaddleLite的关联和区别
深度学习·图像识别
十有久诚7 小时前
TaskRes: Task Residual for Tuning Vision-Language Models
人工智能·深度学习·提示学习·视觉语言模型
PD我是你的真爱粉7 小时前
GPTo1论文详解
人工智能·深度学习
ziwu11 小时前
植物病害识别系统Python+卷积神经网络算法+图像识别+人工智能项目+深度学习项目+计算机课设项目+Django网页界面
人工智能·深度学习·图像识别