编译高博十四讲代码遇到依赖项g2o和cholmod的坑

1. 找不到g2o库!在CMakeLists.txt中使用指令 message(STATUS "${G2O_FOUND}") 打印结果为NO。html

问题描述:bash

CMakeLists.txt 中采用以下命令寻找g2o库。架构

# g2o find_package( G2O REQUIRED ) include_directories( ${G2O_INCLUDE_DIRS} )

科普时间:find_package() 会在模块路径中寻找FindNAME.cmake文件,再经由此文件寻找库全部文件,包括头文件,静态库(*.a),动态库(*.so),这种查找方法称为模块模式。更多详情参考此连接ui

因为我把g2o安装在 /usr/local/g2o 路径中,不在FindNAME.cmake的默认查找路径中,所以一直找不到。spa

解决方法:.net

在CMakeLists.txt中进行修改,以下所示,命令行

set(CMAKE_PREFIX_PATH "/usr/local/g2o") find_package( G2O REQUIRED ) message(STATUS "${G2O_INCLUDE_DIR}") include_directories( ${G2O_INCLUDE_DIR} )

同时在FindG2O.cmake中,将 NO_DEFAULT_PATH 注释掉。以下所示,3d

FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h ${G2O_ROOT}/include $ENV{G2O_ROOT}/include /usr/local/include ... #NO_DEFAULT_PATH )

若是指定了NO_DEFAULT_PATH选项,全部NO_*选项都会被激活,致使 set(CMAKE_PREFIX_PATH "/usr/local/g2o") 设置的路径被跳过。code

 

2. 运行make进行编译时,出现以下报错,htm

/usr/bin/ld: cannot find -lg2o_core /usr/bin/ld: cannot find -lg2o_stuff /usr/bin/ld: cannot find -lg2o_types_slam3d

问题描述:

编译执行文件时使用 target_link_libraries() 连接上述三个动态库文件,在 /usr/local/g2o/lib 中能够找到这些文件,从报错能够判断应该是找不到正确的连接路径。

解决方法:

在CMakeList.txt中添加以下命令行,设置动态库所在的绝对路径。

link_directories("/usr/local/g2o/lib")

关于在cmake中添加头文件目录,连接动态库、静态库的操做参考这个连接

 

3. 运行make编译代码,报错以下,

/home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_numeric.o): In function `cholmod_super_numeric':
cholmod_super_numeric.c:(.text+0xe78): undefined reference to `dsyrk_' cholmod_super_numeric.c:(.text+0xf76): undefined reference to `dgemm_' cholmod_super_numeric.c:(.text+0x129c): undefined reference to `dpotrf_' cholmod_super_numeric.c:(.text+0x13a2): undefined reference to `dtrsm_' cholmod_super_numeric.c:(.text+0x1dd6): undefined reference to `zherk_' cholmod_super_numeric.c:(.text+0x1ed4): undefined reference to `zgemm_' cholmod_super_numeric.c:(.text+0x2286): undefined reference to `zpotrf_' cholmod_super_numeric.c:(.text+0x23b2): undefined reference to `ztrsm_' cholmod_super_numeric.c:(.text+0x2dcb): undefined reference to `zherk_' cholmod_super_numeric.c:(.text+0x2ec9): undefined reference to `zgemm_' cholmod_super_numeric.c:(.text+0x325c): undefined reference to `zpotrf_' cholmod_super_numeric.c:(.text+0x337c): undefined reference to `ztrsm_' /home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_solve.o): In function `cholmod_super_lsolve':
cholmod_super_solve.c:(.text+0x548): undefined reference to `ztrsm_' cholmod_super_solve.c:(.text+0x5f2): undefined reference to `zgemm_' cholmod_super_solve.c:(.text+0x876): undefined reference to `dtrsm_' cholmod_super_solve.c:(.text+0x91d): undefined reference to `dgemm_' cholmod_super_solve.c:(.text+0xad0): undefined reference to `dtrsv_' cholmod_super_solve.c:(.text+0xb5c): undefined reference to `dgemv_' cholmod_super_solve.c:(.text+0xcc6): undefined reference to `ztrsv_' cholmod_super_solve.c:(.text+0xd55): undefined reference to `zgemv_' /home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_solve.o): In function `cholmod_super_ltsolve':
cholmod_super_solve.c:(.text+0x133b): undefined reference to `zgemm_' cholmod_super_solve.c:(.text+0x13c9): undefined reference to `ztrsm_' cholmod_super_solve.c:(.text+0x169a): undefined reference to `dgemm_' cholmod_super_solve.c:(.text+0x1721): undefined reference to `dtrsm_' cholmod_super_solve.c:(.text+0x18bf): undefined reference to `dgemv_' cholmod_super_solve.c:(.text+0x1912): undefined reference to `dtrsv_' cholmod_super_solve.c:(.text+0x1a9d): undefined reference to `zgemv_' cholmod_super_solve.c:(.text+0x1af7): undefined reference to `ztrsv_'

问题描述:

由报错第一行能够断定该报错与Cholmod库有关。没法正确连接Cholmod库。

查看cmake输出内容,以下所示,

Found CHOLMOD: /home/gordon/kalibr_ws/devel/include/suitesparse

能够肯定寻找cholmod库的结果是suitesparse库(目前不清楚这两个库的关系,先将它们等同起来)。我以前在kalibr_ws中安装了suitesparse库,同时,g2o的readme.md也让我在根目录下安装了suitesparse库。想到kalibr_ws是采用catkin_build编译的,其架构跟cmake一定不一致,所以尝试换成根目录下的库。

解决方法:

在 ~/.bashrc 中去除kalibr_ws的环境变量,重启终端。可经过 echo $PATH 命令查看该环境变量是否被移除。或者,暂时将kalibr_ws中的devel文件夹暂时移除。使用 cmake 从新连接库文件,获得以下结果,

Found CHOLMOD: /usr/include/suitesparse

至此便可编译成功。

相关文章
相关标签/搜索