建议按照这篇文章走一遍,应该可以编译成功
https://blog.csdn.net/u013019296/article/details/70052027
然后在: ./build_ros.sh 出现错误:
错误1
Building ROS nodes
mkdir: cannot create directory ‘build’: File exists
[rosbuild] Building package ORB_SLAM2
[rosbuild] Error from directory check: /opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py /home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2
1
Traceback (most recent call last):
File “/opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py”, line 46, in
raise Exception
Exception
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/private.cmake:102 (message):
[rosbuild] rospack found package “ORB_SLAM2” at “”, but the current
directory is “/home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2”. You
should double-check your ROS_PACKAGE_PATH to ensure that packages are found
in the correct precedence order.
Call Stack (most recent call first):
/opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:177 (_rosbuild_check_package_location)
CMakeLists.txt:4 (rosbuild_init)
– Configuring incomplete, errors occurred!
See also “/home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/CMakeFiles/CMakeOutput.log”.
make: *** No targets specified and no makefile found. Stop.
解决办法:
sudo ln -s /home/<用户名>/ORB_SLAM2/Examples/ROS/ORB_SLAM2 /opt/ros/kinetic/share/ORB_SLAM2
然后继续 ./build_ros.sh
若提示build目录已经存在,那是因为你先前编译生成了build,但是是残缺的
解决:
/ORB_SLAM2/Examples/ROS/ORB_SLAM2 找到build删除重新编译
若再不能编译成功,参照错误2
参考:https://blog.csdn.net/weixin_40931266/article/details/81059763
错误2
/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/RGBD.dir/build.make:218: recipe for target ‘…/RGBD’ failed
make[2]: * […/RGBD] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/RGBD.dir/all’ failed
make[1]: * [CMakeFiles/RGBD.dir/all] Error 2
make[1]: * 正在等待未完成的任务….
/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: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:218: 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
Makefile:127: recipe for target ‘all’ failed
make: * [all] Error 2
参考:https://blog.csdn.net/sinat_38343378/article/details/78883919#commentsedit
解决办法:
1、直接在目录点放大镜搜索:
libboost_system.so
libboost_system.so.1.58.0
libboost_filesystem.so
libboost_filesystem.so.1.58.0
把这四个文件复制到ORB_SLAM2/lib
2、将ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中加入库目录,具体为
在set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/…/…/…/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/…/…/…/Thirdparty/g2o/lib/libg2o.so
P
R
O
J
E
C
T
S
O
U
R
C
E
D
I
R
/
.
.
/
.
.
/
.
.
/
l
i
b
/
l
i
b
O
R
B
S
L
A
M
2.
s
o
之
后
加
入
{PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so 之后加入
PROJECTSOURCEDIR/../../../lib/libORBSLAM2.so之后加入{PROJECT_SOURCE_DIR}/…/…/…/lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/…/…/…/lib/libboost_system.so
继续重新编译
最终/ORB_SLAM2/Examples/ROS/ORB_SLAM2 目录下有这些文件就说明编译成功了