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

g2o doesn't find its own functions in ROS

asked 2013-09-28 23:37:15 -0500

ubisum gravatar image

Hello everyone.
I designed a ROS package that needs g2o library for SLAM.
I first tried to download and install it via shell, then I tried, as a test, to make some inclusions:

#include "/opt/ros/fuerte/include/g2o/types/slam2d/vertex_se2.h"
#include "/opt/ros/fuerte/include/g2o/types/slam2d/vertex_point_xy.h"
#include "/opt/ros/fuerte/include/g2o/types/slam2d/edge_se2.h"
#include "/opt/ros/fuerte/include/g2o/types/slam2d/edge_se2_pointxy.h"
#include "/opt/ros/fuerte/include/g2o/types/slam2d/types_slam2d.h"

#include "/opt/ros/fuerte/include/g2o/core/sparse_optimizer.h"
#include "/opt/ros/fuerte/include/g2o/core/block_solver.h"
#include "/opt/ros/fuerte/include/g2o/core/factory.h"
#include "/opt/ros/fuerte/include/g2o/core/optimization_algorithm_factory.h"
#include "/opt/ros/fuerte/include/g2o/core/optimization_algorithm_gauss_newton.h"
#include "/opt/ros/fuerte/include/g2o/solvers/csparse/linear_solver_csparse.h"

rosmake built without any issue the package, even when I added

using namespace g2o;

Then, I added a line of code that I actually need:

SparseOptimizer optimizer;

It gave origin to this error:

 CMakeFiles/thesis_main.dir/src/messageListener.o: In function `messageListener':
  /home/ubisum/fuerte_workspace/thesis_pack/src/messageListener.cpp:36: undefined reference to `g2o::SparseOptimizer::SparseOptimizer()'
  CMakeFiles/thesis_main.dir/src/thesis_main.o: In function `~messageListener':
  /home/ubisum/fuerte_workspace/thesis_pack/src/messageListener.h:44: undefined reference to `g2o::SparseOptimizer::~SparseOptimizer()'

As a second attempt, I downloaded vslam package from web, entered its subfolder /g2o and from inside it I ran build.
As a consequence, ROS found a new package g2o, as shown by rospack list; then I updated the manifest file in my package:

<package>
  <description brief="thesis_pack">

     thesis_pack

  </description>
  <author>Biagio</author>
  <license>BSD</license>
  <review status="unreviewed" notes=""/>
  <url>http://ros.org/wiki/thesis_pack</url>
  <depend package="roscpp"/>
  <depend package="rospy"/>
  <depend package="tf"/>
  <depend package="nav_msgs"/>
  <depend package="g2o"/>


</package>

leaving inclusions and g2o's namespace declaration in my .cpp file, but the error continues to remain. Do you know how to solve the problem?

thanks for help

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-09-29 00:54:19 -0500

tfoote gravatar image

updated 2013-09-29 03:01:32 -0500

dornhege gravatar image

I would recommend that you slow down in all your downloading and hacking and hard coding paths. For example you should not be doing things like hard coding the full paths to include files as you example include above.

Also to make things easier to help you please copy and paste your actual commands you are running. Because "build" as stated above is not a command that you can actually run.

Your "original" error is just a linking error, which means that you already had the package enough to compile against. You need to use the cmake command target_link_libraries to make sure to link your executable or library against the g2o library.

edit flag offensive delete link more

Comments

thanks for your answer. the procedure of entering vslam's subdirectory /g2o and running "build" was proposed by someone on the web who states to have solved my same problem. as a newbie, I trusted and tried to do the same. regarding commands i used, not too much to say: after BUILD in vslam/g2o...

ubisum gravatar image ubisum  ( 2013-09-30 02:40:25 -0500 )edit

... I used rosmake in ROS' g2o package (with no error) and did the same in mine, getting the error i reported in post. i'm not feeling very confident with my installation of g2o as a ROS' package, so maybe i should use the library i installed by shell. how should i use target_link_libraries?

ubisum gravatar image ubisum  ( 2013-09-30 02:43:26 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-09-28 23:37:15 -0500

Seen: 1,170 times

Last updated: Sep 29 '13