ORB-SLAM2编译错误

昨天晚上帮大四学弟在Ubuntu16.04(ROS-Kinetic)上编译ORB-SLAM2,在执行build.sh脚本时出现如下错误:

ORB-SLAM2编译错误_第1张图片

错误信息如下:

Build type: Release
-- Using flag -std=c++11.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wang/SLAM/src/ORB_SLAM2/build
Scanning dependencies of target ORB_SLAM2
[  3%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/System.cc.o
[  6%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/Tracking.cc.o
[  9%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LocalMapping.cc.o
[ 12%] Building CXX object CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o
/home/wang/SLAM/src/ORB_SLAM2/src/LoopClosing.cc: In member function ‘void ORB_SLAM2::LoopClosing::CorrectLoop()’:
/home/wang/SLAM/src/ORB_SLAM2/src/LoopClosing.cc:417:20: warning: use of an operand of type ‘bool’ in ‘operator++’ is deprecated [-Wdeprecated]
         mnFullBAIdx++;
                    ^~
In file included from /usr/include/c++/8/map:61,
                 from /home/wang/SLAM/src/ORB_SLAM2/Thirdparty/DBoW2/DBoW2/BowVector.h:14,
                 from /home/wang/SLAM/src/ORB_SLAM2/include/Frame.h:27,
                 from /home/wang/SLAM/src/ORB_SLAM2/include/MapPoint.h:25,
                 from /home/wang/SLAM/src/ORB_SLAM2/include/KeyFrame.h:24,
                 from /home/wang/SLAM/src/ORB_SLAM2/include/LoopClosing.h:24,
                 from /home/wang/SLAM/src/ORB_SLAM2/src/LoopClosing.cc:21:
/usr/include/c++/8/bits/stl_map.h: In instantiation of ‘class std::map, Eigen::aligned_allocator > >’:
/home/wang/SLAM/src/ORB_SLAM2/src/LoopClosing.cc:439:21:   required from here
/usr/include/c++/8/bits/stl_map.h:122:21: error: static assertion failed: std::map must have the same value_type as its allocator
       static_assert(is_same::value,
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CMakeFiles/ORB_SLAM2.dir/build.make:134: recipe for target 'CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o' failed
make[2]: *** [CMakeFiles/ORB_SLAM2.dir/src/LoopClosing.cc.o] Error 1
CMakeFiles/Makefile2:178: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failed
make[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

具体原因不详,在网上找到解决办法:打开LoopClosing.h,将

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
        Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;

改为

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>,
        Eigen::aligned_allocator<std::pair<KeyFrame *const, g2o::Sim3> > > KeyFrameAndPose;

如下所示:

ORB-SLAM2编译错误_第2张图片

然后重新编译即可通过。


参考网址:http://freebsd.1045724.x6.nabble.com/usr-include-c-v1-map-837-5-error-static-assert-failed-quot-Allocator-value-type-must-be-same-type-as-td6106482.html

你可能感兴趣的:(SLAM学习,视觉SLAM)