ubuntu18.04 安装g2o_viewer,遇到的所有坑和解决方法

举报
振华OPPO 发表于 2022/11/30 20:50:54 2022/11/30
【摘要】 踩坑1 cmake时报错: Could NOT find QGLVIEWER (missing: QGLVIEWER_LIBRARY)1、可以安装需要的qt4依赖库,再次cmake如果解决则不需要往下看:sudo apt-get install libqt4-devsudo apt-get install libqglviewer-dev-qt4sudo apt-get install li...
踩坑1
cmake时报错: Could NOT find QGLVIEWER (missing: QGLVIEWER_LIBRARY)

1、可以安装需要的qt4依赖库,再次cmake如果解决则不需要往下看:

sudo apt-get install libqt4-dev
sudo apt-get install libqglviewer-dev-qt4
sudo apt-get install libsuitesparse-dev

2、安装需要的qt5依赖库,qt4依赖库可删可不删,两者可以共存:

sudo apt-get install libqt5-dev
sudo apt-get install libqglviewer-dev-qt5
sudo apt-get install libsuitesparse-dev

3、接着修改g2o/cmake_modules里面的 FindQGLViewer.cmake文件,让cmake能够找到它。就是在find_library(QGLVIEWER_LIBRARY_RELEASE)和find_library(QGLVIEWER_LIBRARY_DEBUG)中添加下QGLViewer-qt5:

# Need to find both Qt{4,5} and QGLViewer if the QQL support is to be built
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtXml QtOpenGL QtGui)
IF(NOT Qt4_FOUND)
	FIND_PACKAGE(Qt5 QUIET COMPONENTS Core Xml OpenGL Gui Widgets)
	IF(NOT Qt4_FOUND AND NOT Qt5_FOUND)
		MESSAGE("Qt{4,5} not found. Install it and set Qt{4,5}_DIR accordingly")
		IF (WIN32)
			MESSAGE("  In Windows, Qt5_DIR should be something like C:/Qt/5.4/msvc2013_64_opengl/lib/cmake/Qt5")
		ENDIF()
	ENDIF()
ENDIF()

FIND_PATH(QGLVIEWER_INCLUDE_DIR qglviewer.h
    /usr/include/QGLViewer
    /opt/local/include/QGLViewer
    /usr/local/include/QGLViewer
    /sw/include/QGLViewer
    ENV QGLVIEWERROOT
  )

find_library(QGLVIEWER_LIBRARY_RELEASE
  NAMES qglviewer-qt4 qglviewer QGLViewer QGLViewer2 QGLViewer-qt5
  PATHS /usr/lib
        /usr/local/lib
        /opt/local/lib
        /sw/lib
        ENV QGLVIEWERROOT
        ENV LD_LIBRARY_PATH
        ENV LIBRARY_PATH
  PATH_SUFFIXES QGLViewer QGLViewer/release
)
find_library(QGLVIEWER_LIBRARY_DEBUG
  NAMES dqglviewer dQGLViewer dQGLViewer2 QGLViewerd2 QGLViewer-qt5
  PATHS /usr/lib
        /usr/local/lib
        /opt/local/lib
        /sw/lib
        ENV QGLVIEWERROOT
        ENV LD_LIBRARY_PATH
        ENV LIBRARY_PATH
  PATH_SUFFIXES QGLViewer QGLViewer/release
)

if(QGLVIEWER_LIBRARY_RELEASE)
  if(QGLVIEWER_LIBRARY_DEBUG)
    set(QGLVIEWER_LIBRARY optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG})
  else()
    set(QGLVIEWER_LIBRARY ${QGLVIEWER_LIBRARY_RELEASE})
  endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(QGLVIEWER DEFAULT_MSG
  QGLVIEWER_INCLUDE_DIR QGLVIEWER_LIBRARY)

4、重新cmake,这次不会报错了,显示-- Found QGLVIEWER: /usr/include/QGLViewer

踩坑2
g2o_viewer: error while loading shared libraries: libg2o_viewer.so: cannot open shared object file: No such file or directory

1、sudo gedit /etc/ld.so.conf打开配置文件,在新的一行加上include /usr/local/lib,保存退出。

2、然后输入sudo ldconfig回车使配置生效。

在这里插入图片描述
3、终端输入g2o_viewer,应该可以成功打开g2o_viewer的窗口。

在这里插入图片描述

踩坑3
运行g2o_viewer时显示realloc(): invalid pointer 已放弃 (核心已转储)

1、修改g2o/cmake_modules里面的 FindQGLViewer.cmake文件,加粗的就是添加的内容:

find_library(QGLVIEWER_LIBRARY_RELEASE
NAMES qglviewer-qt4 QGLViewer-qt4 qglviewer QGLViewer QGLViewer2

2、将g2o删除干净,即删除它的头文件、库文件以及可执行文件:

sudo rm -r /usr/local/include/g2o /usr/local/lib/libg2o* /usr/local/bin/g2o*

3、删除源代码中的build文件夹,然后重新编译安装g2o:

mkdir build
cd build
cmake ..
make
sudo make install

4、终端任意位置输入g2o_viewer,即可打开g2o_viewer程序:

在这里插入图片描述
5、File——>Load——>result.g2o,打开如图:

在这里插入图片描述

参考文献
https://blog.csdn.net/qq_42995327/article/details/118681435
https://www.freesion.com/article/73111375902/
https://www.manongdao.com/article-979898.html

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。