在编译ROS下的ORB-SLAM2时,需要重新编译源文件./build_ros.sh
但在运行时出现下列问题:
/usr/bin/ld: CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: 无法添加符号: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:182: recipe for target '../Stereo' failed
make[2]: *** [../Stereo] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
通过查阅资料,发现出错原因是libboost_system.so 与libboost_filesystem.so找不到链接目录。
解决方案
1.查找boost_system和boost_filesystem的目录
locate boost_system
/snap/gnome-3-26-1604/70/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
/snap/gnome-3-26-1604/98/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1
locate boost_filesystem
/snap/gnome-3-26-1604/70/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
/snap/gnome-3-26-1604/98/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
/usr/lib/x86_64-linux-gnu/libboost_filesystem.a
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1
2.将libboost_system.so,libboost_system.so.1.65.1,libboost_filesystem.so和libboost_filesystem.so.1.65.1复制到ORB_SLAM2/lib下:
sudo cp -r /usr/lib/x86_64-linux-gnu/libboost_system.so /home/zcj/catkin_ws/src/ORB_SLAM2/lib
sudo cp -r /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 /home/zcj/catkin_ws/src/ORB_SLAM2/lib
sudo cp -r /usr/lib/x86_64-linux-gnu/libboost_filesystem.so /home/zcj/catkin_ws/src/ORB_SLAM2/lib
sudo cp -r /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 /home/zcj/catkin_ws/src/ORB_SLAM2/lib
复制的文件和目标文件夹视自身环境实际情况而定!!!
3.在~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/CMakeLists.txt里添加一句-lboost_system
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system
)
再次编译源文件./build_ros.sh
,问题解决。
来源:CSDN
作者:巴斯克维尔
链接:https://blog.csdn.net/weixin_38978703/article/details/104629562