ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

trouble compiling rospackage with g2o

asked 2013-07-23 00:09:19 -0500

apalomer gravatar image

Hi all!

I am trying to build a basic ros package to do (and optimize) a graph using g2o and data from a robot. The problem is that I can not get to compile even an easy module where I just put few vertices and edges manually (let's say a square) in order to test if I am using propperly the g2o library. I want the latest g2o so I downladed ( and installed it by myself follwing its intructions.

The errors I get when I compile are the following:

  • /usr/local/include/g2o/core/block_solver.hpp:446: undefined reference to `g2o::get_monotonic_time()'

  • /usr/local/include/g2o/core/batch_stats.h:73: undefined reference to `g2o::G2OBatchStatistics::_globalStats'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:126: undefined reference to `g2o::csparse_extension::cs_cholsolsymb(cs_sparse const, double, cs_symbolic const, double, int*)'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:176: undefined reference to `g2o::MarginalCovarianceCholesky::~MarginalCovarianceCholesky()'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:173: undefined reference to `g2o::MarginalCovarianceCholesky::MarginalCovarianceCholesky()'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:174: undefined reference to `g2o::MarginalCovarianceCholesky::setCholeskyFactor(int, int, int, double, int)'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:175: undefined reference to `g2o::MarginalCovarianceCholesky::computeCovariance(double**, std::vector<int, std::allocator<int=""> > const&)'

  • /usr/local/include/g2o/solvers/csparse/linear_solver_csparse.h:176: undefined reference to `cs_nfree'

I obviously skept the parts of the error message where it points to my code.

My CMakeList.txt is:

cmake_minimum_required(VERSION 2.4.6)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

find_package(Eigen REQUIRED)

set(g2o_DIR /usr/local/bin/g2o)

#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory

rosbuild_add_executable(g2o_mvm src/g2o_mvm.cpp)

Thank you very much!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-07-23 03:00:05 -0500

juandhv gravatar image

G2O_INCLUDE_DIRS is not defined previously, as mention. So, we have corrected as follows:

SET(G2O_LIBS g2o_cli g2o_ext_freeglut_minimal g2o_simulator g2o_solver_slam2d_linear g2o_types_icp g2o_types_slam2d g2o_core g2o_interface g2o_solver_csparse g2o_solver_structure_only g2o_types_sba g2o_types_slam3d g2o_csparse_extension g2o_opengl_helper g2o_solver_dense g2o_stuff g2o_types_sclam2d g2o_viewer g2o_ext_csparse g2o_parser g2o_solver_pcg g2o_types_data g2o_types_sim3 cxsparse )

rosbuild_add_executable(g2o_mvm src/g2o_mvm.cpp) target_link_libraries(g2o_mvm ${G2O_LIBS})

In ubuntu, g2o can be installed directly from the repository (ros-<distro>-libg2o), however we have built it from the source code.

edit flag offensive delete link more


Thanks! That totally solved the problem!

apalomer gravatar image apalomer  ( 2013-07-24 00:22:33 -0500 )edit

answered 2013-07-23 01:12:15 -0500

gvdhoorn gravatar image

updated 2013-07-23 01:15:57 -0500

You're not linking your executable with the g2o library. The errors you get come from the linker, which is informing you it cannot find any of the symbols you are referencing. Something along the lines of

link_directories (/path/to/where/you/installed/g2o/libraries)
target_link_libraries (g2o_mvm some_g2o_library)

should solve this.

Edit: where does the G2O_INCLUDE_DIRS variable come from? You're adding it to your include directories, but it doesn't seem to get set by any earlier statements.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-07-23 00:09:19 -0500

Seen: 3,551 times

Last updated: Jul 23 '13