1.首先确保你已经安装了最新版本的cmake。
验证方法:在终端输入:cmake -version即
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~$ cmake -version
cmake version 3.5.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
就可以看到自己的版本了。
2.以源代码安装的形式安装g2o。
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~$ Git clone https://github.com/RainerKuemmerle/g2o.git
默认是装在用户主目录下的,其目录名为g2o。
进入g2o:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~$ cd ~/g2o
显示如下:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o$
在g2o目录下创建一个新的名字为build的子目录,并进入build;
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o$ mkdir build
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o$ cd build
显示如下:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$
安装一些依赖项:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$ sudo apt-get install build-essential cmake libcholmod2.1.2 libsuitesparse-metis-3.1.0 libsuitesparse-metis-dbg libsuitesparse-metis-dev freeglut3 freeglut3-dev freeglut3-dbg qt4-qmake libqglviewer2 libqglviewer-dev libqglviewer-doc libeigen3-dev libeigen3-doc
其中libcholmod2.1.2 libsuitesparse-metis-3.1.0 libsuitesparse-metis-dbg libsuitesparse-metis-dev在Ubuntu 16.04中装不了,可用其他相关的package代替。那么怎么找出这些相关的package呢?
可以使用apt-cache search <package_name>寻找。
例如在终端输入
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$ apt-cache search libcholmod,
这时终端显示:
libcholmod3.0.6 - sparse Cholesky factorization library for sparse matrices
这时可以安装libcholmod3.0.6代替libcholmod2.1.2。名字里有libsuitesparse的依赖项也类似操作
依赖项都安装完后,执行:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$ cmake ..
则终端会显示如下类似内容:
--The C compiler identification is GNU 4.8.2
--The CXX compiler identification is GNU 4.8.2
--Check for working C compiler: /usr/bin/cc
--Check for working C compiler: /usr/bin/cc -- works
--Detecting C compiler ABI info
--Detecting C compiler ABI info - done
--Check for working CXX compiler: /usr/bin/c++
--Check for working CXX compiler: /usr/bin/c++ -- works
--Detecting CXX compiler ABI info
--Detecting CXX compiler ABI info - done
--Compiling on Unix
--Found CHOLMOD: /usr/include/suitesparse
--Looking for sgemm_
--Looking for sgemm_ - found
--A library with BLAS API found.
--Looking for cheev_
--Looking for cheev_ - found
--A library with LAPACK API found.
--Found CHOLMOD and its dependencies
--Found CSPARSE: /usr/include/suitesparse
--Try OpenMP C flag = [-fopenmp]
--Performing Test OpenMP_FLAG_DETECTED
--Performing Test OpenMP_FLAG_DETECTED - Success
--Try OpenMP CXX flag = [-fopenmp]
--Performing Test OpenMP_FLAG_DETECTED
--Performing Test OpenMP_FLAG_DETECTED - Success
--Found OpenMP: -fopenmp
--Looking for XOpenDisplay in/usr/lib/x86_64-Linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
--Looking for XOpenDisplay in/usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so- found
--Looking for gethostbyname
--Looking for gethostbyname - found
--Looking for connect
--Looking for connect - found
--Looking for remove
--Looking for remove - found
--Looking for shmat
--Looking for shmat - found
--Looking for IceConnectionNumber in ICE
--Looking for IceConnectionNumber in ICE - found
--Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
--Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so
--Compiling with OpenGL support
--Looking for Q_WS_X11
--Looking for Q_WS_X11 - found
--Looking for Q_WS_WIN
--Looking for Q_WS_WIN - not found
--Looking for Q_WS_QWS
--Looking for Q_WS_QWS - not found
--Looking for Q_WS_MAC
--Looking for Q_WS_MAC - not found
--Found Qt4: /usr/bin/qmake (found version "4.8.6")
--Found QGLVIEWER: /usr/include/QGLViewer
--Compiling g2o apps
--Compiling g2o examples
--Compiling with GCC
--Performing Test COMPILER_SUPPORTS_CXX11
--Performing Test COMPILER_SUPPORTS_CXX11 - Success
--Performing Test COMPILER_SUPPORTS_CXX0X
--Performing Test COMPILER_SUPPORTS_CXX0X - Success
--Found Eigen3: /usr/include/eigen3 (Required is at least version"2.91.0")
--Configuring done
--Generating done
--Build files have been written to: /home/zhuquan/g2o/build
然后在终端输入make:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$ make
最后,在终端输入sudo make install 安装:
zhuquan@zhuquan-HP-Z230-Tower-Workstation:~/g2o/build$ sudo make install
如果编译没有出错,就会在/usr/local/include看到g2o的包含文件,在usr/local/lib看到g2o的库文件,在usr/local/bin看到g2o的可执行文件。