How to clone, build, and link g2o framework in C++

血红的双手。 提交于 2021-02-11 06:25:42

问题


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

I am a newbie in C++ dependencies.

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

The structure is as following:

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

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()

I left findG2O.cmake untouched as it is in https://github.com/RainerKuemmerle/g2o/blob/master/cmake_modules/FindG2O.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?

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

Error message was:

/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"

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?


回答1:


The config.h is generated after executing the command

 cmake ..

in the folder

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.

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

MY_PROJECT/Thirdparty/g2o/build/g2o

Or you can also use the command

 make install

to copy this file to the install path.

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

/home/user/include/g2o

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

set (G2O_ROOT  /home/user)

before the find_package.

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

include_directories(${G2O_INCLUDE_DIR}


来源:https://stackoverflow.com/questions/58680427/how-to-clone-build-and-link-g2o-framework-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!