[无人车] 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
)
相关推荐
千天夜2 分钟前
激活函数解析:神经网络背后的“驱动力”
人工智能·深度学习·神经网络
m0_523674219 分钟前
技术前沿:从强化学习到Prompt Engineering,业务流程管理的创新之路
人工智能·深度学习·目标检测·机器学习·语言模型·自然语言处理·数据挖掘
小言从不摸鱼2 小时前
【AI大模型】ELMo模型介绍:深度理解语言模型的嵌入艺术
人工智能·深度学习·语言模型·自然语言处理·transformer
python15611 小时前
基于驾驶员面部特征的疲劳检测系统
python·深度学习·目标检测
LittroInno12 小时前
Tofu AI视频处理模块视频输入配置方法
人工智能·深度学习·计算机视觉·tofu
铭瑾熙13 小时前
深度学习之 LSTM
人工智能·深度学习·lstm
SEVEN-YEARS15 小时前
BERT框架详解
人工智能·深度学习·bert
OpenBayes15 小时前
OpenBayes 一周速览丨VASP 教程上线!HPC 助力材料计算;AllClear 公共云层去除数据集发布,含超 23k 个全球分布的兴趣区域
人工智能·深度学习·机器学习·自然语言处理·开源·数据集·大语言模型
双木的木16 小时前
集智书童 | YOLOv8架构的改进:POLO 模型在多类目标检测中的突破 !
人工智能·python·深度学习·yolo·目标检测·机器学习·计算机视觉
金蝶软件小李16 小时前
C#画图板的详细示例代码
图像处理·深度学习·计算机视觉