Rosanswers logo

hi you all. I'm trying to implement a list of odometry measurements and I defined nodes in .h and .cpp files. Then, in a client class Stage_listener.cpp(having an associated .h file that, I guess, it's not useful to include here), I try to create a node :

#include "ros/ros.h"
#include "nav_msgs/Odometry.h"
#include "geometry_msgs/Pose.h"
#include "geometry_msgs/Point.h"
#include "stdio.h"
#include "sensor_msgs/LaserScan.h"
#include "stage_listener.h"
#include "odom_node.h"
//#include "tf/transform_listener.h"

void stage_listener::addOdomNode (const nav_msgs::Odometry mes){
    geometry_msgs::Pose robot_pose = mes.pose.pose;
    geometry_msgs::Point robot_point = robot_pose.position;
    //float xCoord = robot_point.x;
    //float yCoord = robot_point.y;
    //float zCoord = robot_point.z;

    odom_node on;
    //on.xCoord = robot_point.x;
    //double orientation = tf::getYaw(robot_pose.orientation);

int main(){}

Here are the two files I used to define the odometric nodes. This is the header:

#include "ros/ros.h"

class odom_node{
    float xCoord;
    float yCoord;
    float angle;
    std::string frame_id;

And this is the associated .cpp file:

#include "odom_node.h"


The latter is very simple since there are no functions to be implemented; now I get an error:

[100%] Building CXX object CMakeFiles/stage_listener.dir/src/stage_listener.o
In file included from /home/ubisum/fuerte_workspace/beginner/src/stage_listener.cpp:8:0:
/home/ubisum/fuerte_workspace/beginner/src/odom_node.h:3:7: error: redefinition of ‘class odom_node’
/home/ubisum/fuerte_workspace/beginner/src/odom_node.h:3:7: error: previous definition of ‘class odom_node’

I can't get rid of it. Do you have any idea? Thanks for your help and sorry for my boring ROS/C++ newbie questions :)

Originally posted by ubisum on ROS Answers with karma: 23 on 2012-11-19

Post score: 0

Original comments

Comment by ubisum on 2012-11-20:
thanks for your suggestion, Lorenz sadly, i was given a project and c++ at the same time and expiration date for delivery forces not to dedicate much time to learning deeply c++

anyway, i had added in meanwhile #ifndef etc... now i get a new error: "undefined reference to `odom_node::odom_node()"

Comment by ubisum on 2012-11-20:
the error appears when i write "odom_node on;" in stage_listener.cpp

Comment by Lorenz on 2012-11-20:
The problem now is the same as in your previous question. You are not linking together all your C++ files. I don't think you will be able to solve your assignment until you learn C++.


1 Answer 1


Rosanswers logo

You are probably missing the #ifndef guards in your header file. In C++ you need to add:

#ifndef FOO_H
#define FOO_H

... header file contents ...


I really suggest that you dive into C++ a little more before continuing with ROS. A solid knowledge of that language will save you a lot of time.

Originally posted by Lorenz with karma: 22731 on 2012-11-20

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.