g2o编译及配置

对于ubuntu14.04来说g2o的编译和配置还是比较容易的,只不过今天走了一段弯路,很是上火。现在写出我掉进去的坑,希望其他人不要再踩了。建议参考:http://www.ithao123.cn/content-10682274.html
1.首先在https://github.com/RainerKuemmerle/g2o.git
下载g2o包,按要求安装依赖项:
cmake
libeigen3-dev
libsuitesparse-dev
Qt4: libqt4-dev, qt4-qmake, libqglviewer-dev
Qt5: libqt5-dev, qt5-qmake, libqglviewer-dev

2.编译、安装:
mkdir build
cd build
cmake ../
make
sudo make install
注意:这里“sudo make install”教程漏写了(坑死哥哥了)。
用命令”sudo find / -name g2o”看到“/usr/local/include/g2o”和“/usr/local/bin/g2o”就ok了。
3.我要在一个ros包里用,所以在我的包的CMakeList.txt中加上(参照某位大神的博客):

# 添加g2o的依赖
# 因为g2o不是常用库,要添加它的findg2o.cmake文件
LIST( APPEND CMAKE_MODULE_PATH /home/szm/g2o/cmake_modules )  
SET( G2O_ROOT /usr/local/include/g2o )
find_package(G2O REQUIRED)
IF(G2O_FOUND)
    include_directories(${G2O_INCLUDE_DIR})
    message("G2O lib is found:" ${G2O_INCLUDE_DIR})
ENDIF(G2O_FOUND)

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
  include
  ${CSPARSE_INCLUDE_DIR}
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
  /usr/local/include # Location when using 'make system_install'
  /usr/include       # More usual location (e.g. when installing using a package)
)

## Specify additional locations for library files
link_directories(
  /usr/local/lib # Location when using 'make system_install'
  /usr/lib       # More usual location (e.g. when installing using a package)
)

....
target_link_libraries(depth_only  ${catkin_LIBRARIES} KeyFrame g2o_core g2o_types_slam3d g2o_solver_csparse g2o_stuff g2o_csparse_extension)

我还遇到一个错误:

depth_only.cpp:(.text+0x80fd): undefined reference to `g2o::SparseOptimizer::SparseOptimizer()'
.......

这是因为我没链接g2o相应的库。

你可能感兴趣的:(g2o编译及配置)