笔者自己惨痛经验,系统安装不下10次来回。所以想把这些完整过程记录下来,供大家学习和参考。所有的安装建议尽量源码安装。
1:首先安装git:
sudo apt install git
2:下载slam源码:
git clone https://github.com/gaoxiang12/slambook2
3:安装IDE工具,clion:(笔者用的,感觉还不错,也可以是其它的)
CLion 官方下载地址是:Download CLion: A Smart Cross-Platform IDE for C and C++Download the latest version of CLion for Windows, macOS or Linux.https://www.jetbrains.com/clion/download/#section=linux解压安装:解压后在bin文件打开终端
./clion.sh
用clion打开工程,打开最外面的cmakelists.txt, 然后按照里面包含的库安装。
4:安装Eigen库:
sudo apt-get install libeigen3-dev
5:安装Opencv,书中用的是3.1.0:
参考:ubuntu18.04安装opencv3.4.5 - 简书
OpenCV官网下载:Releases - OpenCV
文章图片
https://opencv.org/releases/page/6/先安装依赖项:
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
解压后进入opencv的文件里,打开终端,创建Build文件,用于安装:
mkdir build
cd build
然后执行cmake,生成makefile
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
提示这样算完成***************************************************************************
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/devin/Devin/Tools/opencv-3.1.0/build
devin@devin-ThinkPad-X1-Carbon-Gen-9:~/Devin/Tools/opencv-3.1.0/build$
编译
make -j8 #用8个线程编译,加快速度,也可以去掉-j8
安装
sudo make install
查看安装结果
pkg-config --cflags --libs opencv
配置(好像不用也行)
安装完后配置
sudo gedit /etc/ld.so.conf.d/opencv.conf
打开文件可能是空白的,没有关系,继续下一步,在文件末尾添加打开文件可能是空白的,没有关系,继续下一步,在文件末尾添加
/usr/local/lib
使配置生效
sudo ldconfig
添加环境变量
sudo gedit /etc/bash.bashrc
在文件最后添加
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
使环境变量生效
source /etc/bash.bashrc
6:安装:pangolin
参考:https://blog.csdn.net/qq_49331639/article/details/115024110
源码下载:
git clone https://github.com/stevenlovegrove/Pangolin.git
首先安装Pangolin所需依赖
sudo apt-get install libglew-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
接下来在Pangolin文件夹下开始安装:
mkdir build
cd build
cmake ..
make -j2
sudo make install
7:安装Sophus
参考:https://blog.csdn.net/m0_43422224/article/details/122852322?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-1-122852322.pc_agg_new_rank&utm_term=%E5%AE%89%E8%A3%85sophus&spm=1000.2123.3001.4430
文章图片
https://blog.csdn.net/m0_43422224/article/details/122852322?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-1-122852322.pc_agg_new_rank&utm_term=%E5%AE%89%E8%A3%85sophus&spm=1000.2123.3001.4430
先安装fmt:(信赖项)
源码下载:https://fmt.dev/8.1.1/
安装
mkdir build
cd build
cmake ..
make
sudo make install
源码下载:
git clone https://github.com/strasdat/Sophus.git
安装
mkdir build
cd build
cmake ..makesudo make install
8:G2o/ceres安装
下载源码:https://github.com/RainerKuemmerle/g2o
安装依赖:
sudo apt-get install qt5-qmake qt5-default libqglviewer-dev-qt5 libsuitesparse-dev libcxsparse3 libcholmod3
安装
mkdir build
cd build
cmake ..
make -j4
sudo make install
Ceres源码下载:
git clone https://github.com/ceres-solver/ceres-solver.git
依赖项安装
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3 libgflags-dev libgoogle-glog-dev libgtest-dev
安装:
mkdir build
cd build
cmake ..
make
sudo make install
9: glog安装
git clone https://github.com/google/glog
sudo apt-get install autoconf automake libtool
cd glog
./autogen.sh //如果没有可以跳过
./configure //如果没有可以跳过mkdir build
cd build
cmake ..
make -j 24
sudo make install
10: gflags安装:
参考:https://blog.csdn.net/kenjianqi1647/article/details/106598057
源码下载:
git clone https://github.com/gflags/gflags.git
【SLAM|<<Slam十四讲>> ch13环境安装】安装:
mkdir build
cd build
cmake ..
make
sudo make install
11:gtest安装
参考:https://blog.csdn.net/qq_36251561/article/details/85319547
Ubuntu直接通过控制台安装
sudo apt-get install libgtest-dev
编译链接库,进入gtest文件夹
cd /usr/src/gtest
编译
#没有安装Cmake的请先安装cmake
sudo mkdir build
cd build
sudo cmake ..
sudo make
将生成的libgtest.a 和 libgtest_main.a 拷贝到系统的lib路径下
sudo cp libgtest.a /usr/local/lib
sudo cp libgtest_main.a /usr/local/lib
到此为止,环境已经搭建完毕,
12: 安装CSparse
参考:https://blog.csdn.net/qq_40574708/article/details/105437809
sudo apt-get install libsuitesparse-dev
13:安装Pthread
参考:https://blog.csdn.net/n_fly/article/details/88601197
sudo apt-get install glibc-doc
sudo apt-get install manpages-posix manpages-posix-dev
14: 错误修改:
出现了/usr/bin/ld:找不到-lglut…recipe for target ‘…/lib/libmyslam.so’ failed的错误
[6/8] Linking CXX shared library ../lib/libmyslam.so
FAILED: ../lib/libmyslam.so
: && /usr/bin/c++ -fPIC -O3 -DNDEBUG-shared -Wl,-soname,libmyslam.so -o ../lib/libmyslam.so src/CMakeFiles/myslam.dir/frame.cpp.o src/CMakeFiles/myslam.dir/mappoint.cpp.o src/CMakeFiles/myslam.dir/map.cpp.o src/CMakeFiles/myslam.dir/camera.cpp.o src/CMakeFiles/myslam.dir/config.cpp.o src/CMakeFiles/myslam.dir/feature.cpp.o src/CMakeFiles/myslam.dir/frontend.cpp.o src/CMakeFiles/myslam.dir/backend.cpp.o src/CMakeFiles/myslam.dir/viewer.cpp.o src/CMakeFiles/myslam.dir/visual_odometry.cpp.o src/CMakeFiles/myslam.dir/dataset.cpp.o-Wl,-rpath,/usr/local/lib/usr/local/lib/libopencv_videostab.so.3.1.0/usr/local/lib/libopencv_superres.so.3.1.0/usr/local/lib/libopencv_stitching.so.3.1.0/usr/local/lib/libopencv_shape.so.3.1.0/usr/local/lib/libopencv_photo.so.3.1.0/usr/local/lib/libopencv_objdetect.so.3.1.0/usr/local/lib/libopencv_calib3d.so.3.1.0/usr/local/lib/libpango_glgeometry.so/usr/local/lib/libpango_plot.so/usr/local/lib/libpango_python.so/usr/local/lib/libpango_scene.so/usr/local/lib/libpango_tools.so/usr/local/lib/libpango_video.so-lGL-lGLU-lGLEW-lglut-lg2o_core-lg2o_stuff-lg2o_types_sba-lg2o_solver_csparse-lg2o_csparse_extension/usr/local/lib/libgtest.a/usr/local/lib/libgtest_main.a/usr/local/lib/libglog.so/usr/local/lib/libgflags.a-lpthread-lcxsparse-lfmt/usr/local/lib/libopencv_features2d.so.3.1.0/usr/local/lib/libopencv_ml.so.3.1.0/usr/local/lib/libopencv_highgui.so.3.1.0/usr/local/lib/libopencv_videoio.so.3.1.0/usr/local/lib/libopencv_imgcodecs.so.3.1.0/usr/local/lib/libopencv_flann.so.3.1.0/usr/local/lib/libopencv_video.so.3.1.0/usr/local/lib/libopencv_imgproc.so.3.1.0/usr/local/lib/libopencv_core.so.3.1.0/usr/local/lib/libpango_geometry.so/usr/local/lib/libtinyobj.so/usr/local/lib/libpango_display.so/usr/local/lib/libpango_vars.so/usr/local/lib/libpango_windowing.so/usr/local/lib/libpango_opengl.so-lGLEW-lOpenGL-lGLX-lGLU/usr/local/lib/libpango_image.so/usr/local/lib/libpango_packetstream.so/usr/local/lib/libpango_core.so-lrt-lpthread && :
/usr/bin/ld: 找不到 -lglut
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
或者是编译之后不报错 ,但是lib下没有libmyslam.so文件,这是因为缺少包,执行如下命令,安装freeglut即可
sudo apt-get install freeglut3-dev
推荐阅读
- SLAM|Linux 配置《视觉SLAM十四讲》环境的步骤
- c++|为什么每一名程序员都应该学习 C++()
- opencv从入门到放弃|opencv C艹(色彩空间转换,像素最值,二值化,LUT)
- 人工智能|深蓝学院-多传感器融合定位课程-第3章-3D激光里程计II
- C++|在路上
- C++STL|deque容器详解
- c++|基于C++的即时通信软件设计
- 网络|node-red、nodejs与JavaScript之间的区别与联系
- 每日一练|每日一练--(陶陶摘苹果)(n边形划分)