/usr/bin/ld: CMakeFiles/global_planning_node.dir/src/global_planning_node.cpp.o: in function main.cold': global_planning_node.cpp:(.text.unlikely+0x273): undefined reference to tf::TransformListener::~TransformListener()' /usr/bin/ld: CMakeFiles/global_planning_node.dir/src/global_planning_node.cpp.o: in function main': global_planning_node.cpp:(.text.startup+0xc64): undefined reference to tf::Transformer::DEFAULT_CACHE_TIME' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xc92): undefined reference to tf::TransformListener::TransformListener(ros::Duration, bool)' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xd7a): undefined reference to tf::Transformer::lookupTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::Time const&, tf::StampedTransform&) const' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xe74): undefined reference to tf::TransformListener::~TransformListener()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/global_planning_node.dir/build.make:246: /home/juan/catkin_ws/devel/.private/putn/lib/putn/global_planning_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:207: CMakeFiles/global_planning_node.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function rcvVelodyneCallBack(sensor_msgs::PointCloud2<std::allocator<void> > const&)': local_obs.cpp:(.text+0xa0b): undefined reference to tf::Transformer::waitForTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::Time const&, ros::Duration const&, ros::Duration const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const' /usr/bin/ld: local_obs.cpp:(.text+0xc74): undefined reference to tf::TransformListener::transformPoint(std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, geometry_msgs::PointStamped<std::allocator<void> > const&, geometry_msgs::PointStamped<std::allocator<void> >&) const' /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function main.cold': local_obs.cpp:(.text.unlikely+0x37d): undefined reference to tf::TransformListener::~TransformListener()' /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function main':local_obs.cpp:(.text.startup+0x62a): undefined reference to tf::Transformer::DEFAULT_CACHE_TIME' /usr/bin/ld: local_obs.cpp:(.text.startup+0x64d): undefined reference to tf::TransformListener::TransformListener(ros::Duration, bool)' /usr/bin/ld: local_obs.cpp:(.text.startup+0x6dc): undefined reference to tf::TransformListener::~TransformListener()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/local_obs_node.dir/build.make:246: /home/juan/catkin_ws/devel/.private/putn/lib/putn/local_obs_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:612: CMakeFiles/local_obs_node.dir/all] Error 2 make: *** [Makefile:141: all] Error 2解释编译时出现这个问题的原因,并说说如何解决
时间: 2023-09-14 20:12:52 浏览: 228
这个编译错误是因为链接器找不到tf库的符号引用。tf库是一个用于处理坐标变换的库,它提供了TransformListener和Transformer等类。
要解决这个问题,你需要确保tf库正确地链接到你的项目中。以下是一些可能的解决方法:
1. 确保tf库已经正确地安装在你的系统中。如果你使用的是ROS,可以通过运行以下命令来安装tf库:
```
sudo apt-get install ros-<distro>-tf
```
这里的 `<distro>` 是你正在使用的ROS发行版,例如`melodic`或`noetic`。
2. 确保在你的CMakeLists.txt文件中正确地添加了tf库的依赖项。你可以在`find_package`命令后添加以下行来链接tf库:
```
target_link_libraries(your_target_name ${catkin_LIBRARIES} tf)
```
这里的 `your_target_name` 是你的目标可执行文件的名称。
3. 如果你的项目使用了其他依赖项,例如tf2或tf2_ros,你可能还需要添加它们的链接库。例如:
```
target_link_libraries(your_target_name ${catkin_LIBRARIES} tf tf2 tf2_ros)
```
4. 确保你的源代码文件中包含了正确的头文件引用。对于tf库,你可能需要包含`<tf/transform_listener.h>`和`<tf/transform_broadcaster.h>`。
尝试以上方法后,重新编译你的项目,应该能够解决链接错误。如果问题仍然存在,请确保在编译过程中没有其他错误或警告,并仔细检查你的代码和编译配置。
阅读全文