新建一个功能包及.cpp文件后报错tf2_ros::Buffer::Buffer(ros::Duration, bool)’未定义的引用
/opt/ros/kinetic/include/tf2_ros/buffer.h:51:对‘vtable for tf2_ros::Buffer’未定义的引用
/opt/ros/kinetic/include/tf2_ros/buffer.h:51:对‘vtable for tf2_ros::Buffer’未定义的引用
/opt/ros/kinetic/include/tf2_ros/buffer.h:51:对‘tf2::BufferCore::~BufferCore()’未定义的引用
/opt/ros/kinetic/include/tf2_ros/buffer.h:51:对‘tf2::BufferCore::~BufferCore()’未定义的引用
CMakeFiles/demo01_tfs.dir/src/demo01_tfs.cpp.o:在函数‘main’中:
/home/salad/catkin_ws/demo04_ws/src/tf03_tfs/src/demo01_tfs.cpp:38:对‘tf2_ros::Buffer::Buffer(ros::Duration, bool)’未定义的引用
/home/salad/catkin_ws/demo04_ws/src/tf03_tfs/src/demo01_tfs.cpp:39:对‘tf2_ros::TransformListener::TransformListener(tf2::BufferCore&, bool)’未定义的引用
![](https://img-blog.csdnimg.cn/img_convert/3a449d5478347d484f64e6994a055a99.png)
原因:未能使用tf2等依赖,缺少相关依赖
解决:在与src同级的Cmakelists中将tf2,tf2_ros,tf2_geometry_msgs,std_msgs,turtlesim等依赖都添加进来,再次编译成功通过
![](https://img-blog.csdnimg.cn/img_convert/cd06a74ed02ad0411a2c0300b9e94bbe.png)