顺序如下

  • 底层环境
  • Eigen
  • Pangolin
  • fmt
  • Sophus
  • Opencv

1. 编译环境

一定首先要选择好镜像位置、一般教育网选择清华源、也可以由系统自己选择
其次、安装底层环境。

sudo apt-get update 
sudo apt-get upgrade
  1. cmake

    sudo apt-get install build-essential cmake
  2. git

    sudo apt-get install git 

2. 工作环境

  1. Eigen安装

    sudo install libeigen3-dev

    这个是安装在了
    /usr/include/eigen3
    有需要的话自己换位置

  2. Pangolin安装

    // 安装Pangolin所需依赖项
    sudo apt-get install libglew-dev
    sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
    // 下载并Pangolin
    cd && git clone https://github.com/stevenlovegrove/Pangolin.git && cd Pangolin && mkdir build && cd build && cmake .. && sudo make install
    // 分拆指令为
    // 到home/user下并下载
    cd && git clone https://github.com/stevenlovegrove/Pangolin.git
    // 进入Pangolin文件夹并创建编译文件夹
    cd Pangolin && mkdir build && cd build
    // cmake
    cmake ..
    // 如果不报错、则可以安装
    sudo make install
  3. Sophus安装

    //我这里需要先安装fmt、不知为啥
    cd && git clone https://github.com/fmtlib/fmt.git && cd fmt && mkdir build && cd build && cmake .. && sudo make install
    // 然后安装 Sophus
    cd && git clone https://github.com/strasdat/Sophus.git && cd Sophus && mkdir build && cd build && cmake .. && make && sudo make install
  4. Ceres-Solver安装

    # google-glog + gflags
    sudo apt-get install libgoogle-glog-dev libgflags-dev
    # Use ATLAS for BLAS & LAPACK
    sudo apt-get install libatlas-base-dev
    # SuiteSparse and CXSparse (optional)
    sudo apt-get install libsuitesparse-dev
    # 安装
    cd && git clone https://github.com/ceres-solver/ceres-solver.git && cd ceres-solver && mkdir build && cd build && cmake .. && make -j3 && make test && sudo make install
    # 如果报错 'exclusive_scan' is not a member of 'std'
    # 则需要安装g++11 和 gcc11 、可以看以下博文
    https://blog.csdn.net/miracle_world/article/details/124340606
  5. g2o安装

    # 安装依赖
    sudo apt-get install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
    # 下载并安装g2o
    cd && git clone https://github.com/RainerKuemmerle/g2o.git && mkdir g2o/build && cd g2o/build && cmake .. && make && sudo make install
    # 如果提示cmake版本较低,可以看以下博文
    https://blog.csdn.net/w5688414/article/details/107019919
    # 即
    sudo apt remove --purge cmake
    hash -r
    sudo snap install cmake --classic

    6.opencv安装

    #    先是背景环境
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev  libx264-dev libatlas-base-dev gfortran libgtk2.0-dev libjpeg-dev libpng-dev
    # 下载并进入相应的安装环境
    cd && git clone https://github.com/opencv/opencv.git && cd opencv && mkdir build && cd build
    # build
    cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
    # make 要使用4核去编译、会很快很快
    sudo make -j4
    # 安装
    sudo make install
    # 环境变量
    sudo gedit /etc/ld.so.conf.d/opencv.conf
    # 添加
    /usr/local/lib
    # 加载配置
    sudo ldconfig
    # 环境变量
    sudo gedit /etc/bash.bashrc
    # 末尾添加
    PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
    export PKG_CONFIG_PATH
    # 加载
    source /etc/bash.bashrc
    sudo upadtedb