对符号“_ZN3ros10NodeHandle9subscribeERNS_16SubscribeOptionsE”的未定义引用

undefined reference to symbol '_ZN3ros10NodeHandle9subscribeERNS_16SubscribeOptionsE'

我只是想在 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。此外,您需要将 ${catkin_LIBRARIES} 添加到 target_link_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}
)