ORB_SLAM2编译出现问题

在: ./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/zqzy/catkin_ws/src/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

 

错误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

解决方法:

执行如下命令:

搜索这四个文件,把这四个文件复制到/home/zqzy/catkin_ws/src/ORB_SLAM2/lib:
libboost_system.so
libboost_system.so.1.58.0
libboost_filesystem.so
libboost_filesystem.so.1.58.0

sudo find / -name libboost_system.so

sudo find / -name libboost_system.so.1.58.0

sudo find / -name libboost_filesystem.so

sudo find / -name libboost_filesystem.so.1.58.0

ORB_SLAM2编译出现问题_第1张图片

sudo cp /usr/lib/x86_64-linux-gnu/libboost_system.so /home/zqzy/catkin_ws/src/ORB_SLAM2/lib
 
sudo cp /usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0 /home/zqzy/catkin_ws/src/ORB_SLAM2/lib
 
sudo cp /usr/lib/x86_64-linux-gnu/libboost_filesystem.so /home/zqzy/catkin_ws/src/ORB_SLAM2/lib
 
sudo cp /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0 /home/zqzy/catkin_ws/src/ORB_SLAM2/lib

 

修改ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt:

将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
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
)

改为: 

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
${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
)

继续重新编译

错误3:

/home/zqzy/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc: In member function ‘void ORB_SLAM2::ViewerAR::Run()’:
/home/zqzy/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc:233:23: error: ‘usleep’ was not declared in this scope
         usleep(mT*1000);
                       ^
CMakeFiles/MonoAR.dir/build.make:200: recipe for target 'CMakeFiles/MonoAR.dir/src/AR/ViewerAR.cc.o' failed
make[2]: *** [CMakeFiles/MonoAR.dir/src/AR/ViewerAR.cc.o] Error 1
CMakeFiles/Makefile2:820: recipe for target 'CMakeFiles/MonoAR.dir/all' failed
make[1]: *** [CMakeFiles/MonoAR.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

解决方法:

找到相应的cc文件,添加头文件 #include ,即可

 

最终/ORB_SLAM2/Examples/ROS/ORB_SLAM2 目录下有这些文件就说明编译成功了

ORB_SLAM2编译出现问题_第2张图片


参考:https://blog.csdn.net/weixin_43513725/article/details/93896650

你可能感兴趣的:(SLAM)