ros::package::getPath用法:
#include <ros/package.h>
std::string path = ros::package::getPath("package_name");
在 CMakeList.txt 中修改两处:
一是 find_package 模块中加入 roslib,例如
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
roslib
)
二是 add_executable 后添加对 catkin_LIBRARIES 的链接,例如
add_executable(main ./src/main.cpp)
target_link_libraries(main ${catkin_LIBRARIES})