如何在C ++中克隆,构建和链接g2o框架 [英] How to clone, build, and link g2o framework in C++

查看:185
本文介绍了如何在C ++中克隆,构建和链接g2o框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Ubuntu 18.04上的C ++ 11项目中使用g2o库,但是无法使构建正常工作.我有所有的依赖关系.但是我无法通过CMakeLists.txt将g2o库链接到我的项目

I want to use g2o library in my C++11 project on Ubuntu 18.04, but I cannot make build working. I have all the dependencies. But I cannot link g2o library to my project via CMakeLists.txt

我是C ++依赖项的新手.

I am a newbie in C++ dependencies.

我尝试克隆 https://github.com/RainerKuemmerle/g2o 存储库并进行构建用cmake.

I've tried cloning https://github.com/RainerKuemmerle/g2o repository and building it with cmake.

结构如下:

MY_PROJECT
|__ cmake_modules
|__ project_src
|__ CMakeLists.txt

|__ Thirdparty
   |____ g2o
       |____ bin
       |____ build
       |____ cmake_modules # findG2O.cmake
       |____ lib # .so shared libraries (all of them, like 20)
       |____ g2o
            |____ core # headers and source files
            |____ solvers
            |____ types
       |____ CMakeLists.txt

我从g2o内部将cmake_modules添加到my_project的CMakeLists.txt中然后尝试使用find_package找到它,但找不到它.

I added cmake_modules from inside g2o to the CMakeLists.txt of my_project and than try to find it with find_package but it is not found.

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/g2o/cmake_modules)


find_package(G2O REQUIRED)
if(NOT G2O_FOUND)
   message(FATAL_ERROR "G2O not found.")
endif()

我保持findG2O.cmake不变,因为它处于 https:///github.com/RainerKuemmerle/g2o/blob/master/cmake_modules/FindG2O.cmake

I left findG2O.cmake untouched as it is in https://github.com/RainerKuemmerle/g2o/blob/master/cmake_modules/FindG2O.cmake

我应该更改find​​G2O.cmake吗?我不太了解发生了什么.我应该如何继续进行源代码构建和链接?

Should I change the findG2O.cmake? I do not really understand what is going on. How should I proceed with building out of the source and linking?

我在StackOverflow的任何地方都没有找到解决问题的精确答案,但也许我只是不知道自己在寻找什么.

I haven't found precise answer to my problem anywhere on StackOverflow but maybe I just didn't know what I was searching for.

错误消息为:

/home/miki/ORB_SLAM2/Thirdparty/g2o/g2o/types/sim3/types_seven_dof_expmap.h:29:10: fatal error: g2o/config.h: No such file or directory #include "g2o/config.h"

当我尝试更改为#include"../../config.h"时,它起作用了.如何在CMakeLists中解决该问题,所以不必更改ThirdParty库中的所有包含项?

When I tried to change to #include "../../config.h" it worked. How can I solve it in CMakeLists so I do not have to change all includes in ThirdParty library?

推荐答案

config.h是在执行命令后生成的

The config.h is generated after executing the command

 cmake ..

在文件夹中

MY_PROJECT/Thirdparty/g2o/build

,此文件包含一些信息,例如您尝试使用哪种类型的已使用浮点或库.我认为此类信息将用于自动修改某些代码块.

, and this file has some information like what type of used floating point or library you try to use. I think such information will be used to modify some code blocks automatically.

默认情况下,文件config.h的位置在文件夹中

By default, the location of file config.h is in the folder

MY_PROJECT/Thirdparty/g2o/build/g2o

或者您也可以使用命令

 make install

将此文件复制到安装路径.

to copy this file to the install path.

如果您的$ {CMAKE_PREFIX_INTALL}是/home/user/,则config.h文件的位置在文件夹中

If your ${CMAKE_PREFIX_INTALL} is /home/user/, then the location of file config.h is in the folder

/home/user/include/g2o

如果要使用find_package查找g2o库,则需要编写

And if you want to find g2o libraries with find_package, then you need to write

set (G2O_ROOT  /home/user)

在find_package之前.

before the find_package.

最后,将标头路径添加到CMakeLists.txt中,例如

Finally, add the header path into CMakeLists.txt, like

include_directories(${G2O_INCLUDE_DIR}

这篇关于如何在C ++中克隆,构建和链接g2o框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆