SLAM14讲 ch6 g2o曲线拟合程序问题-G2OConfig.cmake
Could not find a package configuration file provided by "G2O" with any of the following names:
G2OConfig.cmake
g2o-config.cmake
这一讲包含了一个用g2o库进行曲线拟合的实例,但是在按照书中实际步骤实际运行发现了几个问题。
亦或者出现这么一个尴尬的场面:利用高博的代码编译可以通过,自己新建的工程,复制高博的代码,build后出现问题。
在使用cmake编译中,出现了以下报错:
1 By not providing "FindG2O.cmake" in CMAKE_MODULE_PATH this project has
2 asked CMake to find a package configuration file provided by "G2O", but
3 CMake did not find one.
4
5 Could not find a package configuration file provided by "G2O" with any of
6 the following names:
7
8 G2OConfig.cmake
9 g2o-config.cmake
10
11 Add the installation prefix of "G2O" to CMAKE_PREFIX_PATH or set "G2O_DIR"
12 to a directory containing one of the above files. If "G2O" provides a
13 separate development package or SDK, be sure it has been installed.
编译出错的原因指向CMakeLists.txt中,没找到cmake的配置文件:
G2OConfig.cmake
g2o-config.cmake
也没有:
FindG2O.cmake
打开安装g2o的文件夹发现,安装在/usr/local/include/g2o下的G2O库里面并没有上述两个文件。那这两个文件来源于哪里呢?
这要从安装g2o库开始说起,按照如下办法应该能解决上述问题:
1)g2o库的的依赖项安装
书中所写命令如下:
sudo apt-get install libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3 libcholmod-dev
sudo apt-get install libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3 libcholmod-dev
但是最后一项(libcholmod-dev)会提示不能安装,此时应该用tab键进行补全完成安装
2)下载g2o库文件
打开www.github.com后,输入g2o,检索到第一个就是咱们需要的库文件。
或者直接打开这个链接:https://github.com/RainerKuemmerle/g2o
打开终端,下载库文件:
cd /home/whu/Tools/DependentLibrary
git clone https://github.com/RainerKuemmerle/g2o.git
下载完成,至于中间速度很龟速的问题,大家再找找对应的解决办法!
3)安装g2o库
cd g2o
mkdir build
cd build
cmake ..
make -j4
sudo make install
安装完成后,根据安装过程中的终端信息显示,g2o库被安装在/usr/local/include/g2o
进入该目录后发现,确实没有上述问题中的配置文件,在从GitHub下载的库文件(安装包)中搜索:
G2OConfig.cmake
发现该文件位于/home/whu/Tools/DependentLibrary/g2o/build/generated下面。
同时搜索:
FindG2O.cmake
发现该文件位于/home/whu/Tools/DependentLibrary/g2o/cmake_modules下面。
这个就很诡异了,按理说安装完成,对应的链接关系都配置好了的,这。。。
虽然定义了CMAKE_MODULE_PATH,但没有对应的文件和文件夹,也就是没有找到FindG2O.cmake文件
4)解决办法
网上解决办法:找到findg2o.cmake文件的位置,一般在g2o安装包中的"cmake_modules"文件夹中,将整个文件夹复制到相应工程的下面,与build文件夹在同一目录,然后编译可以正常通过。
归根结底,这个问题出在CMakeLists.txt内,没有找到对应的库文件导致的错误。
高博在GitHub中给出的代码如下:
1 cmake_minimum_required( VERSION 2.8 )
2 project( g2o_curve_fitting )
3
4 set( CMAKE_BUILD_TYPE "Release" )
5 set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )
6
7 # 添加cmake模块以使用ceres库
8 list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )
9
10 # 寻找G2O
11 find_package( G2O REQUIRED )
12 include_directories(
13 ${G2O_INCLUDE_DIRS}
14 "/usr/include/eigen3"
15 )
16
17 # OpenCV
18 find_package( OpenCV REQUIRED )
19 include_directories( ${OpenCV_DIRS} )
20
21 add_executable( g2oCurveFitting g2oCurveFitting.cpp )
22 # 与G2O和OpenCV链接
23 target_link_libraries( g2oCurveFitting
24 ${OpenCV_LIBS}
25 g2o_core g2o_stuff
26 )
很遗憾,出错!!!
5)我的解决办法:
进入库文件(安装包)内,打包两个文件:build和cmake_modules
cd /home/whu/Tools/DependentLibrary/g2o
tar -czvf build.tar.gz build/
tar -czvf cmake_modules.tar.gz cmake_modules/
移动至安装目录/usr/local/include/g2o下
重新打开一个终端
sudo cp /home/whu/Tools/DependentLibrary/g2o/build.tar.gz /usr/local/include/g2o/
sudo cp /home/whu/Tools/DependentLibrary/g2o/cmake_modules.tar.gz /usr/local/include/g2o/
解压
cd /usr/local/g2o
sudo tar -xzvf build.tar.gz
sudo tar -xzvf cmake_modules.tar.gz
返回工程,找到CMakeLists.txt
在加载g2o库那里添加如下几句:
#g2o
LIST(G2O_ROOT /usr/local/include/g2o/cmake_modules)
SET(G2O_ROOT /usr/local/include/g2o)
FIND_PACKAGE(G2O REQUIRED)
include_directories(${G2O_INCLUDE_DIRS} “/usr/local/eigen3”)
# 与G2O和OpenCV链接
target_link_libraries( g2oCurveFitting
${OpenCV_LIBS}
${G2O_CORE_LIBRARY}
${G2O_STUFF_LIBRARY}
)
最后整个代码的运行结果如下:
/home/whu/SLAM/SLAM_Test/chapter06/build> /usr/bin/ninja
[1/1] Re-running CMake...
-- Eigen found (include: /usr/include/eigen3, version: 3.3.4)
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- system
-- filesystem
-- date_time
-- iostreams
-- serialization
-- regex
-- The imported target "vtkRenderingPythonTkWidgets" references the file
"/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.
-- The imported target "vtk" references the file
"/usr/bin/vtk"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.
-- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so)
-- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so)
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
** WARNING ** io features related to libusb-1.0 will be disabled
-- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so)
-- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so)
-- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so)
-- looking for PCL_COMMON
-- looking for PCL_KDTREE
-- looking for PCL_OCTREE
-- looking for PCL_SEARCH
-- looking for PCL_SAMPLE_CONSENSUS
-- looking for PCL_FILTERS
-- looking for PCL_2D
-- looking for PCL_GEOMETRY
-- looking for PCL_IO
-- looking for PCL_FEATURES
-- looking for PCL_ML
-- looking for PCL_SEGMENTATION
-- looking for PCL_VISUALIZATION
-- looking for PCL_SURFACE
-- looking for PCL_REGISTRATION
-- looking for PCL_KEYPOINTS
-- looking for PCL_TRACKING
-- looking for PCL_RECOGNITION
-- looking for PCL_STEREO
-- looking for PCL_OUTOFCORE
-- looking for PCL_PEOPLE
-- Eigen found (include: /usr/include/eigen3, version: 3.3.4)
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- system
-- filesystem
-- date_time
-- iostreams
-- serialization
-- regex
-- The imported target "vtkRenderingPythonTkWidgets" references the file
"/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.
-- The imported target "vtk" references the file
"/usr/bin/vtk"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/lib/cmake/vtk-6.3/VTKTargets.cmake"
but not all the files it references.
-- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so)
-- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so)
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
** WARNING ** io features related to libusb-1.0 will be disabled
-- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so)
-- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so)
-- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so)
-- looking for PCL_COMMON
-- looking for PCL_KDTREE
-- looking for PCL_OCTREE
-- looking for PCL_SEARCH
-- looking for PCL_SAMPLE_CONSENSUS
-- looking for PCL_FILTERS
-- looking for PCL_2D
-- looking for PCL_GEOMETRY
-- looking for PCL_IO
-- looking for PCL_FEATURES
-- looking for PCL_ML
-- looking for PCL_SEGMENTATION
-- looking for PCL_VISUALIZATION
-- looking for PCL_SURFACE
-- looking for PCL_REGISTRATION
-- looking for PCL_KEYPOINTS
-- looking for PCL_TRACKING
-- looking for PCL_RECOGNITION
-- looking for PCL_STEREO
-- looking for PCL_OUTOFCORE
-- looking for PCL_PEOPLE
-- Found required Ceres dependency: Eigen version 3.3.4 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found required Ceres dependency: gflags
-- Found Ceres version: 2.0.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, Multithreading]
-- Found required Ceres dependency: Eigen version 3.3.4 in /usr/include/eigen3
-- Found required Ceres dependency: glog
-- Found required Ceres dependency: gflags
-- Found Ceres version: 2.0.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, Multithreading]
-- Configuring done
-- Generating done
-- Build files have been written to: /home/whu/SLAM/SLAM_Test/chapter06/build
[3/6] Building CXX object ceresCurveFitting/CMakeFiles/ceresCurveFitting.dir/ceresCurveFitting.cpp.o
[4/6] Linking CXX executable ceresCurveFitting/ceresCurveFitting
[4/6] Building CXX object gaussNewton/CMakeFiles/gaussNewton.dir/gaussNewton.cpp.o
[5/6] Linking CXX executable gaussNewton/gaussNewton
[5/6] Building CXX object g2oCurveFitthing/CMakeFiles/g2oCurveFitting.dir/g2oCurveFitting.cpp.o
[6/6] Linking CXX executable g2oCurveFitthing/g2oCurveFitting
*** Finished ***
由于项目名定的是g2oCurveFitting,因此需要修改最后的
target_link_libraries( g2oCurveFitting
${OpenCV_LIBS}
${G2O_CORE_LIBRARY}
${G2O_STUFF_LIBRARY}
)
(这个只是我遇见的问题,如果还有其他的问题,欢迎一起交流讨论)
编译信息中有PCL,我的工程很大,引用g2o只是其中一个子工程,所以大家莫奇怪!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)