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?
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}