解决error: undefined reference to g2o::OptimizableGraph::addVertex问题**

error: undefined reference to `g2o::OptimizableGraph::addVertex(g2o::OptimizableGraph::Vertex*, g2o::HyperGraph::Data*)’

error: undefined reference to `g2o::OptimizableGraph::addEdge(g2o::OptimizableGraph::Edge*)’

后来发现ros里面也有g2o的库,然后默认调用了ros里面的g2o。
解决方法:
修改FindG2O.cmake文件
原来的FindG2O.cmake文件为

FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h${G2O_ROOT}/include$ENV{G2O_ROOT}/include$ENV{G2O_ROOT}/usr/local/include/usr/include/opt/local/include/sw/local/include/sw/includeNO_DEFAULT_PATH)# Macro to unify finding both the debug and release versions of the
# libraries; this is adapted from the OpenSceneGraph FIND_LIBRARY
# macro.MACRO(FIND_G2O_LIBRARY MYLIBRARY MYLIBRARYNAME)FIND_LIBRARY("${MYLIBRARY}_DEBUG"NAMES "g2o_${MYLIBRARYNAME}_d"PATHS${G2O_ROOT}/lib/Debug${G2O_ROOT}/lib$ENV{G2O_ROOT}/lib/Debug$ENV{G2O_ROOT}/libNO_DEFAULT_PATH)FIND_LIBRARY("${MYLIBRARY}_DEBUG"NAMES "g2o_${MYLIBRARYNAME}_d"PATHS~/Library/Frameworks/Library/Frameworks/usr/local/lib/usr/local/lib64/usr/lib/usr/lib64/opt/local/lib/sw/local/lib/sw/lib)FIND_LIBRARY(${MYLIBRARY}NAMES "g2o_${MYLIBRARYNAME}"PATHS${G2O_ROOT}/lib/Release${G2O_ROOT}/lib$ENV{G2O_ROOT}/lib/Release$ENV{G2O_ROOT}/libNO_DEFAULT_PATH)FIND_LIBRARY(${MYLIBRARY}NAMES "g2o_${MYLIBRARYNAME}"PATHS~/Library/Frameworks/Library/Frameworks/usr/local/lib/usr/local/lib64/usr/lib/usr/lib64/opt/local/lib/sw/local/lib/sw/lib)IF(NOT ${MYLIBRARY}_DEBUG)IF(MYLIBRARY)SET(${MYLIBRARY}_DEBUG ${MYLIBRARY})ENDIF(MYLIBRARY)ENDIF( NOT ${MYLIBRARY}_DEBUG)ENDMACRO(FIND_G2O_LIBRARY LIBRARY LIBRARYNAME)# Find the core elements
FIND_G2O_LIBRARY(G2O_STUFF_LIBRARY stuff)
FIND_G2O_LIBRARY(G2O_CORE_LIBRARY core)# Find the CLI library
FIND_G2O_LIBRARY(G2O_CLI_LIBRARY cli)# Find the pluggable solvers
FIND_G2O_LIBRARY(G2O_SOLVER_CHOLMOD solver_cholmod)
FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE solver_csparse)
FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE_EXTENSION csparse_extension)
FIND_G2O_LIBRARY(G2O_SOLVER_DENSE solver_dense)
FIND_G2O_LIBRARY(G2O_SOLVER_PCG solver_pcg)
FIND_G2O_LIBRARY(G2O_SOLVER_SLAM2D_LINEAR solver_slam2d_linear)
FIND_G2O_LIBRARY(G2O_SOLVER_STRUCTURE_ONLY solver_structure_only)
FIND_G2O_LIBRARY(G2O_SOLVER_EIGEN solver_eigen)# Find the predefined types
FIND_G2O_LIBRARY(G2O_TYPES_DATA types_data)
FIND_G2O_LIBRARY(G2O_TYPES_ICP types_icp)
FIND_G2O_LIBRARY(G2O_TYPES_SBA types_sba)
FIND_G2O_LIBRARY(G2O_TYPES_SCLAM2D types_sclam2d)
FIND_G2O_LIBRARY(G2O_TYPES_SIM3 types_sim3)
FIND_G2O_LIBRARY(G2O_TYPES_SLAM2D types_slam2d)
FIND_G2O_LIBRARY(G2O_TYPES_SLAM3D types_slam3d)# G2O solvers declared found if we found at least one solver
SET(G2O_SOLVERS_FOUND "NO")
IF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN)SET(G2O_SOLVERS_FOUND "YES")
ENDIF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN)# G2O itself declared found if we found the core libraries and at least one solver
SET(G2O_FOUND "NO")
IF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND)SET(G2O_FOUND "YES")
ENDIF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND)

修改为

FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h${G2O_ROOT}/include$ENV{G2O_ROOT}/include$ENV{G2O_ROOT}/usr/local/include/usr/include/opt/local/include/sw/local/include/sw/includeNO_DEFAULT_PATH)# Macro to unify finding both the debug and release versions of the
# libraries; this is adapted from the OpenSceneGraph FIND_LIBRARY
# macro.MACRO(FIND_G2O_LIBRARY MYLIBRARY MYLIBRARYNAME)FIND_LIBRARY("${MYLIBRARY}_DEBUG"NAMES "g2o_${MYLIBRARYNAME}_d"PATHS${G2O_ROOT}/lib/Debug${G2O_ROOT}/lib$ENV{G2O_ROOT}/lib/Debug$ENV{G2O_ROOT}/libNO_DEFAULT_PATH)FIND_LIBRARY("${MYLIBRARY}_DEBUG"NAMES "g2o_${MYLIBRARYNAME}_d"PATHS~/Library/Frameworks/Library/Frameworks/usr/local/lib/usr/local/lib64/usr/lib/usr/lib64/opt/local/lib/sw/local/lib/sw/libNO_DEFAULT_PATH)FIND_LIBRARY(${MYLIBRARY}NAMES "g2o_${MYLIBRARYNAME}"PATHS${G2O_ROOT}/lib/Release${G2O_ROOT}/lib$ENV{G2O_ROOT}/lib/Release$ENV{G2O_ROOT}/libNO_DEFAULT_PATH)FIND_LIBRARY(${MYLIBRARY}NAMES "g2o_${MYLIBRARYNAME}"PATHS~/Library/Frameworks/Library/Frameworks/usr/local/lib/usr/local/lib64/usr/lib/usr/lib64/opt/local/lib/sw/local/lib/sw/libNO_DEFAULT_PATH)IF(NOT ${MYLIBRARY}_DEBUG)IF(MYLIBRARY)SET(${MYLIBRARY}_DEBUG ${MYLIBRARY})ENDIF(MYLIBRARY)ENDIF( NOT ${MYLIBRARY}_DEBUG)ENDMACRO(FIND_G2O_LIBRARY LIBRARY LIBRARYNAME)# Find the core elements
FIND_G2O_LIBRARY(G2O_STUFF_LIBRARY stuff)
FIND_G2O_LIBRARY(G2O_CORE_LIBRARY core)# Find the CLI library
FIND_G2O_LIBRARY(G2O_CLI_LIBRARY cli)# Find the pluggable solvers
FIND_G2O_LIBRARY(G2O_SOLVER_CHOLMOD solver_cholmod)
FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE solver_csparse)
FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE_EXTENSION csparse_extension)
FIND_G2O_LIBRARY(G2O_SOLVER_DENSE solver_dense)
FIND_G2O_LIBRARY(G2O_SOLVER_PCG solver_pcg)
FIND_G2O_LIBRARY(G2O_SOLVER_SLAM2D_LINEAR solver_slam2d_linear)
FIND_G2O_LIBRARY(G2O_SOLVER_STRUCTURE_ONLY solver_structure_only)
FIND_G2O_LIBRARY(G2O_SOLVER_EIGEN solver_eigen)# Find the predefined types
FIND_G2O_LIBRARY(G2O_TYPES_DATA types_data)
FIND_G2O_LIBRARY(G2O_TYPES_ICP types_icp)
FIND_G2O_LIBRARY(G2O_TYPES_SBA types_sba)
FIND_G2O_LIBRARY(G2O_TYPES_SCLAM2D types_sclam2d)
FIND_G2O_LIBRARY(G2O_TYPES_SIM3 types_sim3)
FIND_G2O_LIBRARY(G2O_TYPES_SLAM2D types_slam2d)
FIND_G2O_LIBRARY(G2O_TYPES_SLAM3D types_slam3d)# G2O solvers declared found if we found at least one solver
SET(G2O_SOLVERS_FOUND "NO")
IF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN)SET(G2O_SOLVERS_FOUND "YES")
ENDIF(G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN)# G2O itself declared found if we found the core libraries and at least one solver
SET(G2O_FOUND "NO")
IF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND)SET(G2O_FOUND "YES")
ENDIF(G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND)

本质就是去掉默认目录,即FIND_LIBRARY只能在指定目录找库。

解决error: undefined reference to g2o::OptimizableGraph::addVertex问题相关推荐

  1. 解决Error: undefined reference to `__android_log_print'

    解决Error: undefined reference to `__android_log_print'     最近在使用Android Studio进行NDK开发时,程序本身是没有问题,但一旦添 ...

  2. 【Qt】报错error: undefined reference to `vtable for的解决方法

    1.问题描述 编译Qt程序时,在某个类构造函数定义处报错: error: undefined reference to `vtable for 2.原因分析 导致错误信息的原因是:子类没有实现父类的纯 ...

  3. Android系统编译so库提示error undefined reference to '__android_log_print问题的解决

    在系统源代码的hardware/qcom下增加psam文件夹,编译源代码要生成libpsam.so库,Android.mk内容 LOCAL_PATH := $(call my-dir) include ...

  4. QT构建编译出现错误error: undefined reference to 的解决办法

    这里要解决问题的是QT构建中的 error: undefined reference to 而不是 undefined reference to vtable for "xxx::xxx&q ...

  5. QT:error: undefined reference to 'xxxx'错误提示,解决方式

    当你执行QT程序时,突然报错了这个错 error: undefined reference to 'xxxx' 表示未定义 函数 只需要把头文件里的 private slots的指定报错的函数去除了就 ...

  6. android error: undefined reference to 的错误分析

    今天,简单讲讲android  error: undefined reference to 的错误分析. 昨天,做jni,连接so库时,android studio出现了这个问题.当时不知道是什么 ...

  7. error: undefined reference to `_imp__glXXX@XX'

    问题: 原文地址: https://blog.csdn.net/hebbely/article/details/69946155 如:error: undefined reference to `_i ...

  8. error: undefined reference to `PathTrace::PathTrace(World*)' (Codeblocks, C++)

    error: undefined reference to `PathTrace::PathTrace(World*)'  说的是`PathTrace::PathTrace(World*)' 没有被& ...

  9. Qt 多线程bug:moc_widget.cpp:-1: error: undefined reference to `Mythread::~Mythread()‘:-1:

    Qt 多线程 moc_widget.cpp:-1: error: undefined reference to `Mythread::~Mythread()' moc_widget.cpp:-1: e ...

最新文章

  1. 百度云加速 ajax,使用百度云加速后网站打开速度慢、广告不显示的解决方法
  2. 阿里达摩院包揽AI领域六大权威榜单冠军:用人类的学习方式超越人类
  3. teamviewer 可用设备上限_2020推荐香河气压罐专业供水设备
  4. 阿里云CDN技术 揭秘
  5. 华为emui10是鸿蒙,昨日,华为EMUI10,鸿蒙系统正式发布!
  6. nbu 恢复oracle数据库,关于使用nbu重定向恢复oracle数据库rman报错
  7. 360加固逆向脱壳之过反调试
  8. 【全网首发】京东商业数据分析师培养计划
  9. .NET 开源项目 StreamJsonRpc 介绍[下篇]
  10. vue项目cordova打包的android应用
  11. Centos 解压软件
  12. boobooke播布客
  13. 输出200以内所有素数(python)
  14. 牙齿,我怎么才能保护你
  15. Windows注册表知识
  16. 普渡机器人服务北京大学
  17. Population and carrying capacity 的第二阶段 :Crowding affects lifetime.
  18. 【数据安全案例】北京购车摇号查询系统出现信息泄露漏洞
  19. 无线路由器有几种工作模式
  20. 基于CNN的海面舰船图像二分类

热门文章

  1. 利用树莓派和花生壳搭建web服务器
  2. 研发团队如何借助Gitlab来做代码review
  3. 计算机视觉:卷积步长(Stride)
  4. lombok和JPA的死递归
  5. ORB-SLAM2源码笔记(1)——框架结构
  6. ecp应用程序中的服务器错误,ECP 运行状况设置疑难解答
  7. SLAM基础——舒尔补介绍
  8. Squid代理服务器应用
  9. CiteSpace学习笔记(三)——数据预处理
  10. 虚拟摄像头Softcam v1.52 汉化注册版