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

摘要:
因为我在/usr/local/g20路径中安装了g2o,而不是在FindNAME.cmake的默认查找路径中,所以我一直找不到它。解决方案:在CMakeLists.txt中进行修改,如下所示,设置find_ packagemessageinclude_同时,在FindG2O.make中,设置注释掉的NO_ DEFAULT _ PATH。如下所示,FIND_PATH如果指定了NO _ DEFAULT _ PATH选项,则所有NO_*选项都将被激活,从而导致跳过逐集设置的路径。link_有关在cmake中添加头文件目录以及链接动态和静态库的操作,请参阅此链接。

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

问题描述:

CMakeLists.txt 中采用如下命令寻找g2o库。

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

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

由于我把g2o安装在 /usr/local/g2o 路径中,不在FindNAME.cmake的默认查找路径中,因此一直找不到。

解决方法:

在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 注释掉。如下所示,

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") 设置的路径被跳过。

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

/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 

至此即可编译成功。

免责声明:文章转载自《编译高博十四讲代码遇到依赖项g2o和cholmod的坑》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ByteBuf使用实例Solon详解(一)- 快速入门下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

gcc编译选项【转】

转自:https://blog.csdn.net/rheostat/article/details/19811407 常用选项 -E:只进行预处理,不编译-S:只编译,不汇编-c:只编译、汇编,不链接-g:包含调试信息-I:指定include包含文件的搜索目录-o:输出成指定文件名 高级选项 -v:详细输出编译过程中所采用的每一个选项-C:预处理时保留注...

Qt使用.lib静态库和.dll动态库文件

我安装的环境是Qt_5_8_0_MSVC2015_64bit,或许不同环境下编译有所不同,我就我自己的安装环境进行叙述一下吧。 1.添加一个新项目,作为静态库项目 2.选择静态库,并完成就可以了 这时候发现生成的项目是个空项目,需要我们自己进行添加.h和.cpp文件,我们建立两个文件mylib.h和mylib.cpp文件,代码如下: mylib.h #...

1. CMake 系列

目录 1. 文件目录结构 2. 库文件源代码 3. 编译生成库文件 1. 文件目录结构 首先创建如下目录结构: └── lib ├── build # ├── CMakeLists.txt └── src # ├── add.c └── add.h 从上面的结构,可以看出博主想实现...

linux升级gcc

情景如下: CentOS7, python3, 以及python3的pip(命名为pip3) 执行 pip3 install sxtwl 时,报错: 省略N字......-std=c11 , 总之就是不支持-std=c11 查阅资料,需要升级gcc,yum只到4.8.5版本, 只好编译安装, 目前最新已经9.x了, 我下载的6.1.0 下载gcc源码...

linux中的strip命令简介------给文件脱衣服【转】

转自:http://blog.csdn.net/stpeace/article/details/47090255 版权声明:本文为博主原创文章,转载时请务必注明本文地址, 禁止用于任何商业用途, 否则会用法律维权。 作为一名Linux开发人员, 如果没有听说过strip命令, 那是很不应该的。 strip这个单词, 大家应该早就学过了...

动态链接库和静态链接库介绍和实例(一)

一、库的介绍库是写好的现有的,成熟的,可以复用的代码。现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常。 本质上来说库是一种可执行代码的二进制形式,可以被操作系统载入内存执行。库有两种:静态库(.a、.lib)和动态库(.so、.dll)。 windows上对应的是(.lib .dll) ,linux上对应的...