orbslam移植到macos下面2

网上查了查c++程序是可以直接在macos电脑上编译成功的,mac上Objective-C++混合编译,如果没有用其他平台的库。所以我是先在网上下载了一个orbslam-os版,先把需要的基本依赖环境配置好,编译成功后(我是直接通过终端编译的,此时还没有用Xcode),把自己的修改过的orbslam放到macos上,然后根据编译报错,进行修改

  1. 问题:

    /src/ORBmatcher.cc:30:9:
    fatal error:
    	'stdint-gcc.h' file not found
    #include <stdint-gcc.h>
    

    措施:#include <stdint-gcc.h>换成下面这个

    #ifdef __APPLE__
    #include<stdint.h>
    #else
    #include<stdint-gcc.h>
    #endif	
    
  2. 问题:

    bVocLoad = mpVocabulary->loadFromBinaryFile(strVocFile) 
    这个方法不存在 src/System.cc下
    因为DBoW2是用的另一个版本
    

    措施:bVocLoad = mpVocabulary->loadFromBinaryFile(strVocFile)换成下面这个,只是读取字典只能以txt的方式,不能二进制的方式就慢了很多

    bVocLoad = mpVocabulary->loadFromTextFile(strVocFile);
    

    同样后面也会有同样的问题,在/tools/bin_vocabulary.cc里面,有2个地方,也没有关于转成二进制的方法,只有txt的方法,暂且先把它该成txt方法跑起来,后期是需要把二进制方法加进去的

  3. 问题:

    No rule to make target '../Thirdparty/DBoW2/lib/libDBoW2.so' , needed by '../lib/libORB_SLAM2.dylib' . Stop.
    

    措施:${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so ${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so换成下面这个

    macos下面生成的不是.so文件,而是.dylilb
    所以换一下cmakeLists.txt里的target_link_libraries下面的
    ${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.dylib
    ${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.dylib
    
  4. 问题

    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:470:39: error: 
      use of undeclared identifier 'mit'; did you mean 'min'?
        for(KeyFrameAndPose::iterator mit=CorrectedSim3.begin(), mend=Co...
                                      ^~~
                                      min
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2454:1: note: 
          'min' declared here
    min(const _Tp& __a, const _Tp& __b, _Compare __comp)
    ^
    In file included from /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/Optimizer.cc:23:
    In file included from /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/Thirdparty/g2o/g2o/core/block_solver.h:30:
    In file included from /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/Thirdparty/g2o/g2o/types/../core/solver.h:32:
    In file included from /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/Thirdparty/g2o/g2o/types/../core/sparse_block_matrix.h:229:
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/Thirdparty/g2o/g2o/types/../core/sparse_block_matrix.hpp:339:45: warning: 
          ISO C++ specifies that qualified reference to 'SparseBlockMatrix' is a
          constructor name rather than a type in this context, despite preceding
          'typename' keyword [-Winjected-class-name]
        typename SparseBlockMatrix<MatrixType>::SparseBlockMatrix* s=new Spa...
                                                ^
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:470:30: error: 
          no member named 'iterator' in 'std::__1::map<ORB_SLAM2::KeyFrame *,
          g2o::Sim3, std::__1::less<ORB_SLAM2::KeyFrame *>,
          Eigen::aligned_allocator<std::__1::pair<const ORB_SLAM2::KeyFrame *,
          g2o::Sim3> > >'
            for(KeyFrameAndPose::iterator mit=CorrectedSim3.begin(), mend=Co...
                ~~~~~~~~~~~~~~~~~^
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:470:92: error: 
          use of undeclared identifier 'mit'; did you mean 'min'?
      ...mit=CorrectedSim3.begin(), mend=CorrectedSim3.end(); mit!=mend; mit++)
                                                              ^~~
                                                              min
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2454:1: note: 
          'min' declared here
    min(const _Tp& __a, const _Tp& __b, _Compare __comp)
    ^
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:470:97: error: 
          use of undeclared identifier 'mend'
      ...mit=CorrectedSim3.begin(), mend=CorrectedSim3.end(); mit!=mend; mit++)
    

    Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:912:5: error: 
          static_assert failed due to requirement 'is_same<std::__1::pair<const
          ORB_SLAM2::KeyFrame *, g2o::Sim3>, std::__1::pair<ORB_SLAM2::KeyFrame
          *const, g2o::Sim3> >::value' "Allocator::value_type must be same type as
          value_type"
        static_assert((is_same<typename allocator_type::value_type, value_type>::value),
        ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:436:21: note: 
          in instantiation of template class 'std::__1::map<ORB_SLAM2::KeyFrame *,
          g2o::Sim3, std::__1::less<ORB_SLAM2::KeyFrame *>,
          Eigen::aligned_allocator<std::__1::pair<const ORB_SLAM2::KeyFrame *,
          g2o::Sim3> > >' requested here
        KeyFrameAndPose CorrectedSim3, NonCorrectedSim3;
                        ^
    /Users/zhangjianhua/Desktop/tool/ORBSLAM_MapSave-master/src/LoopClosing.cc:466:29: error: 
          no viable overloaded operator[] for type
          'ORB_SLAM2::LoopClosing::KeyFrameAndPose' (aka 'map<ORB_SLAM2::KeyFrame *,
          g2o::Sim3, std::less<KeyFrame *>, Eigen::aligned_allocator<std::pair<const
          KeyFrame *, g2o::Sim3> > >')
                NonCorrectedSim3[pKFi]=g2oSiw;
    

    措施:在include/LoopClosing.h把第50行的const 移动了一下

    #ifndef LOOPCLOSING_H
    #define LOOPCLOSING_H
    
    #include "KeyFrame.h"
    #include "LocalMapping.h"
    #include "Map.h"
    #include "ORBVocabulary.h"
    #include "Tracking.h"
    
    #include "KeyFrameDatabase.h"
    
    #include <thread>
    #include <mutex>
    #include "Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h"
    
    namespace ORB_SLAM2
    {
    
    class Tracking;
    class LocalMapping;
    class KeyFrameDatabase;
    
    
    class LoopClosing
    {
    public:
    
    typedef pair<set<KeyFrame*>,int> ConsistentGroup;    
    typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame* const>,
        Eigen::aligned_allocator<std::pair< KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;
    
  5. 问题

    ld: library not found for -lcholmod
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    措施:本来之前的g2o下面是有cholmod的,但是mac版本的g2o,作者并没有把它加进去,导致用不了,但是suitesparse库中已经包含了cholmod库,所以安装cholmod库的任务转变成了在mac系统下安装suitesparse库

    brew install suite-sparse
    然后cmakeLists.txt里面加两行
    find_package(SuiteParse REQUIRED)
    include_directories( ${CSPARSE_INCLUDE_DIR} ${CHOLMOD_INCLUDE_DIR}) 
    去掉target_link_libraries(cholmod)
    然后在cmake_modules下面加一个FindSuiteParse.cmake文件
    

    这样虽然能解决问题,但是后面还是会遇到g2o下面的linear_solver_cholmod.h这个没有,该去哪里导入这样一个框架,错误如下:

    Undefined symbols for architecture x86_64:
      "g2o::OptimizationAlgorithmGaussNewton::OptimizationAlgorithmGaussNewton(g2o::Solver*)", referenced from:
          ORB_SLAM2::Optimizer::BundleAdjustmentICP(std::__1::vector<ORB_SLAM2::MapPoint*, std::__1::allocator<ORB_SLAM2::MapPoint*> >, std::__1::vector<ORB_SLAM2::MapPoint*, std::__1::allocator<ORB_SLAM2::MapPoint*> >, cv::Mat&, cv::Mat&) in Optimizer.cc.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation
    

    一开始的设想是,把之前另一个版本有/g2o/solvers/linear_solver_cholmod.h , /g2o/stuff/sparse_helper.cpp , /g2o/stuff/sparse_helper.h的g2o里面需要的一些文件拷到能在mac上跑起来的g2o里面,修改一下cmakeLists.txt,重新编译,虽然能编译成功,但是orbslam还是没法编译成功(最终我其实还是这么解决的,因为g2o下面的cmakeLists.txt看的不够仔细,少导入了两个模块 g2o/core/optimization_algorithm_gauss_newton.cpp , g2o/core/optimization_algorithm_gauss_newton.h

    然后在网上找到了一个带有linear_solver_cholmod.h的特别大的mac版本的g2o,构造与目前这个差异较大,编译有很多很多错误,感觉不好改
    决定再去尝试直接修改有linear_solver_cholmod.h的g2o(最终没成功),虽然错误很多

    1)使用GCC而不是默认的CLang编译器

    先禁止brew自动检查更新
    export HOMEBREW_NO_AUTO_UPDATE=true
    安装gcc编译器
    brew install gcc
    遇到一个错误:Xcode alone is not sufficient on Mojave.
    按照它的提示,执行下面命令:xcode-select --install
    虽然我已经安装了xcode了,但是上面的命令是要我安装一些命令行工具,仅仅拥有Xcode是不够的
    
    然后设置gcc环境变量
    export CC=gcc-5
    export CXX=g++-5
    export CPP=cpp-5
    export LD=gcc-5
    

    2)找不到``,这似乎和Boost有关

    把-I/usr/local/Cellar/boost/1.59.1/include/boost/tr1/tr1添加到g2o CMakeLists.txt文件中,操作如下
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3 -march=native -I /usr/local/Cellar/boost/1.59.1/include/boost/tr1/tr1")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall  -O3 -march=native -I /usr/local/Cellar/boost/1.59.1/include/boost/tr1/tr1")
    
    1. cmake的时候会遇到一个错:
    could not find compiler set in environment variable cc:
    	gcc-5
    

    解决办法:

    cmake -DCMAKE_CXX_COMPILER=$(which g++) -DCMAKE_C_COMPILER=$(which gcc) ./
    

    4)make的时候会遇到一个问题:

    /usr/local/Cellar/boost/1.59.0/include/boost/tr1/tr1/map:16:12: fatal error: 
          'boost/tr1/detail/config_all.hpp' file not found
    #  include <boost/tr1/detail/config_all.hpp>
    

    仔细一看发现是1.60以后的版本删掉了tr1,而我之前更新了boost,是1.65.1版本,解决办法就是把旧版本下面的tr1文件夹拷到新版本下面(当时想了个蠢办法,就是把1.65.1版本删掉,继续用老版本,但是貌似安装过程中写了一些到类似环境变量一样的配置文件中,所以我直接删除1.65.1文件夹,系统仍然是去找1.65.1,找了许久发现不知道怎么改回去版本,就只能参考谷歌上的把这个版本少的补上去了)

    但是即便有tr1这个目录了,系统仍然会找不到那个config_all.hpp文件,实际上是有的,当时直接把这些文件路径都写成绝对路径,但是后续有很多奇怪的错,能力有限实在解决不了–>然后转到想办法完全卸载掉boost1.65.1,然后用1.60以下的版本

    export HOMEBREW_NO_AUTO_UPDATE=true
    brew uninstall boost
    上面我没有执行成功,然后按终端提示执行下面这个
    brew uninstall --force boost
    然后安装指定版本的boost,但是我安装不下来
    brew install boost@1.58
    brew link boost@1.58 --force --overwrite
    

    结果后面boost1.60一下版本下载不回去了,只能通过源码去安装了,然后暂时放弃,选择去改原本能在mac上跑通,但少了linear_solver_cholmod.h的g2o,最终编译成功了(详见上面)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值