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

时间:2018-08-31 03:23:36

标签: c++ cmake ros

我只是想在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

1 个答案:

答案 0 :(得分:0)

您的链接器在库列表中找不到符号。 调用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}
)