编译build_ros.sh时报错
主要参考:https://github.com/hxiaoxi/SLAM/blob/master/ROS%20%2B%20ORB_SLAM.md
在ros上编译build_ros.sh时报错,出现如下信息:
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/daiwj5/catkin_ws/src/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 <module>
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/daiwj5/catkin_ws/src/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/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found. Stop.
这个时候需要在~/.bashrc文件末尾添加一行路径,如下(如果放在主目录下的话):
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/自己的用户名/catkin_ws/src/ORB_SLAM2/Examples/ROS
接着运行
source ~/.bashrc
可以使用以下命令来检查:
echo $ROS_PACKAGE_PATH
出现/opt/ros/kinetic/share:PATH/ORB_SLAM2/Examples/ROS,正常
echo $ROS_ROOT
出现 /opt/ros/kinetic/share/ros,正常。
接着运行命令
./build_ros.sh
出现以下报错
In file included from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../Thirdparty/g2o/g2o/types/../core/optimizable_graph.h:41:0,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../Thirdparty/g2o/g2o/types/../core/base_vertex.h:30,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h:34,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../include/LoopClosing.h:34,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../include/LocalMapping.h:26,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../include/Tracking.h:31,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../include/System.h:29,
from /home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc:35:
/home/daiwj5/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/../../../Thirdparty/g2o/g2o/types/../core/jacobian_workspace.h:30:22: fatal error: Eigen/Core: No such file or directory
compilation terminated.
CMakeFiles/RGBD.dir/build.make:119: recipe for target 'CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o' failed
make[2]: *** [CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
运行以下命令即可解决
sudo ln -s /usr/include/eigen3/Eigen /usr/local/include/Eigen
再接着往下,可能会出现以下报错:
/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:205: 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
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
这个时候,找到Example/ROS/ORB-SLAM2/目录下的CMakelist.txt文件,在原有文件对应模块中添加:
find_package(Boost COMPONENTS system) #这一行
include_directories(
${Boost_INCLUDE_DIRS} #这一行
)
set(LIBS
${Boost_LIBRARIES} #这一行
)
至此,问题解决,重新编译build_ros.sh,大功告成!