動態鏈接庫 (.so)調用問題;類變量定義

使用方式:需要在一個包去調用另一個包

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);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章