动态链接库 (.so)调用问题;类变量定义

本文详细解析了在ROS环境下,遇到的路径规划库调用失败问题及其解决方法。作者分享了如何通过正确的链接库配置和修正构造函数来避免加载库时出现的未定义符号错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

版权声明:本文为博主原创文章,未经博主允许不得转载,转载注明来源。

使用方式:需要在一个包去调用另一个包

global_planner::hybrid_astar hy1;

问题:

Failed to create the rrt_plan/rrt_planner planner, are you sure it is properly registered and that the containing library is built? Exception: Failed to load library /home/like/c++/catkin_rrt/devel/lib//librrt_lib.so. Make sure that you are calling the PLUGINLIB_EXPORT_CLASS macro in the library code, and that names are consistent between this macro and your XML. Error string: Could not load library (Poco exception = /home/like/c++/catkin_rrt/devel/lib//librrt_lib.so: undefined symbol: _ZN14global_planner12hybrid_astarC1Ev) 

库调用不正确/librrt_lib.so没有调用

解决方式:

1)  target_link_libraries(rrt_lib ${catkin_LIBRARIES} base_local_planner)

当我们使用其他的库的时候,需要加上上面的这句命令去调用其他的库 rrb_lib是自己生成的库 

  ${catkin_LIBRARIES} 是我们这个包里面去调用其他的库 

base_local_planner 这个可加可不加,,上面的命令会全部加入所需要的库

2) 重定义的变量中的构造函数变量的库没有调用 (下面是我的构造函数)

hybrid_astar::hybrid_astar():
  costmap_(NULL),lethal_cost(253), neutral_cost(50),
  convert_offset_(0.5),cx(4846),cy(2816),resolution(0.298582141738734),
  origin_x(0),origin_y(0)
{
    p_calc = new PotentialCalculator(cx, cy);//声明对象
    planner_ = new DijkstraExpansion(p_calc, cx, cy);//声明调用这个规划的基类
    potential_array_ = new float[cx * cy];

    planner_->setHasUnknown(true);
    planner_->setLethalCost(lethal_cost);
    planner_->setNeutralCost(neutral_cost);
    DijkstraExpansion dijkstra(PotentialCalculator* p_calc, int cx, int cy);//定义一个dijistra变量
    rs_publisher = rs_n.advertise<nav_msgs::Path>("/reedsshepp/plan", 1);

}

修改:

hybrid_astar::hybrid_astar():
  costmap_(NULL),lethal_cost(253), neutral_cost(50),
  convert_offset_(0.5),cx(4846),cy(2816),resolution(0.298582141738734),
  origin_x(0),origin_y(0)
{
    rs_publisher = rs_n.advertise<nav_msgs::Path>("/reedsshepp/plan", 1);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值