对符号'_ZN3ros10NodeHandle9subscribeERNS_16SubscribeOptionsE'的未定义引用

undefined reference to symbol '_ZN3ros10NodeHandle9subscribeERNS_16SubscribeOptionsE'

本文关键字:未定义 引用 ZN3ros10NodeHandle9subscribeERNS 符号 16SubscribeOptionsE      更新时间:2023-10-16

我只是想用ROS编译一个程序。我已经链接了所有必要的库,但这个我找不到。我得到的只是代码块中的以下错误(也在 eclipse 中(。

有人知道如何摆脱这个错误吗?甚至需要哪个库?

/usr/bin/ld:CMakeFiles/DistanceKinectDemo.dir/src/DistanceKinectDemo.cpp.o: undefined reference to symbol
'_ZN3ros10NodeHandle9subscribeERNS_16SubscribeOptionsE'
/opt/ros/kinetic/lib/libroscpp.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
gpuvoxelgetpointcloud/CMakeFiles/DistanceKinectDemo.dir/build.make:370: recipe for target 
'/home/pcl_gpu/devel/lib/gpuvoxelgetpointcloud/DistanceKinectDemo' failed
make[2]: *** [/home/shupeng/pcl_gpu/devel/lib/gpuvoxelgetpointcloud/DistanceKinectDemo] Error 1
CMakeFiles/Makefile2:1130: recipe for target 'gpuvoxelgetpointcloud/CMakeFiles/DistanceKinectDemo.dir/all' failed

链接器在库列表中找不到该符号。 调用find_package(catkin REQUIRED COMPONENTS ...时,必须列出组件roscpp。此外,您需要在target_link_libraries呼叫中添加${catkin_LIBRARIES}。 最后,用于链接的库应按依赖项的降序列出,这意味着如果您有其他库依赖于它,则应将${catkin_LIBRARIES}放在target_link_libraries调用的末尾。 最后,您的CMakeLists.txt文件应如下所示:

...
find_package(catkin REQUIRED COMPONENTS roscpp <more packages>)
...
add_executable(DistanceKinectDemo <your cpp files>)
...
target_link_libraries(DistanceKinectDemo
<all your libraries and other dependencies>
${catkin_LIBRARIES}
)