The g2o library is a graph optimization library, which is widely used in slam.
The following are some pits that have been stepped on, for your reference
The first pit
/usr/local/include/g2o/solvers/csparse/csparse_extension.h:27:10: fatal error: cs.h: No such file or directory
27 | #include <cs.h>
| ^~~~ ~~
This is the solution
First, install the csparse library again, and if it has already been installed, it will prompt that it has been installed
sudo apt-get install libsuitesparse-dev
Then find where suitesparse is
locate suitesparse
The result will show some .h files under /usr/include/suitesparse/, including cs.h
Put this path into CMakeLists.txt
include_directories("/usr/include/suitesparse/")
The second pit, undefined reference to `g2o XXX
Many g2o functions cannot be found.
Add the following in CMakeLists.txt.
target_link_libraries(XXX g2o_core g2o_types_slam3d g2o_solver_csparse g2o_stuff g2o_csparse_extension)