g2o
g2o copied to clipboard
Cannot link g2o to ROS project, after building successfully from source and installing to default system paths
I built and installed g2o from source, and calling
which g2o
shows me that the g2o binary is installed to:
/usr/local/bin/g2o
Furthermore, I can find the headers by going to:
/usr/local/include/g2o
which gives the following directories:
EXTERNAL apps autodiff config.h core examples solvers stuff types
However, in my ROS Noetic project's CMakeLists.txt file, when I add
find_package(G2O REQUIRED)
I get the error:
CMake Error at /home/jeff/projects/catkin_ws/src/mapper/CMakeLists.txt:34 (find_package):
By not providing "FindG2O.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "G2O", but
CMake did not find one.
Could not find a package configuration file provided by "G2O" with any of
the following names:
G2OConfig.cmake
g2o-config.cmake
Add the installation prefix of "G2O" to CMAKE_PREFIX_PATH or set "G2O_DIR"
to a directory containing one of the above files. If "G2O" provides a
separate development package or SDK, be sure it has been installed.
I also tried copying over the cmake_modules
directory from the g2o source directory into my project root directory and added the cmake_modules
directory to the CMAKE_MODULE_PATH
with:
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
In this way, I don't get the above error anymore, but if I print out the g2o environment variables using:
message(STATUS "G2O_INCLUDE_DIR: ${G2O_INCLUDE_DIR}")
message(STATUS "G2O_LIBRARIES: ${G2O_LIBRARIES}")
I see the following for the headers:
G2O_INCLUDE_DIR: /usr/local/include
but for the libraries I see a blank path:
G2O_LIBRARIES:
Which causes linking errors if I try and actually use something like g2o::SparseOptimizer
in my project.
So my question is, how in the world do I get CMake to see g2o so I can link my project to it correctly? I feel like what I've tried should have solved the issue, yet I've had no luck. Any help would be appreciated.
There is a ROS package available in ROS1. Did you try using that instead of building from src? See for example, https://github.com/rst-tu-dortmund/teb_local_planner for a package using that.
This still seems to be an issue on master and is not related to ROS. I cant link use this library when built work source.
Edit: It seems to me there is an inconsistency between CMake and the expectation to find "g2o" and "G2O". For example the generated configs are g2oConfig.cmake which is not compatible with find_package(G2O..)
Edit #2. You need to set your cmake module path to point the supplied FindG2O.cmake file:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} <your_path>/g2o/cmake_modules)
It would be nice to clarify this on the README.md. Ideally it should be copied into the cmake/share folder
@RainerKuemmerle can you please provide an answer to this issue?