Ask Your Question
0

Undefined reference error while constructing a list of nodes

asked 2012-11-18 01:19:24 -0600

ubisum gravatar image

Hello everyone I need to construct a list of odometric and laser measurement. For this purpose, I first wrote a .h file:

#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"


class odom_node{
public:
    odom_node();
    ~odom_node();
    float xCoord;
    float yCoord;
    float angle;
    std::string frame_id;
    odom_node *next;
};

class scan_node{
public:
    scan_node();
    float scan[];
    std::string frame_id;
    scan_node *next;
};

class stage_listener{
public:
    stage_listener();

private:
    odom_node odom_graph;
    scan_node scan_list;
    void addOdomNode (const nav_msgs::Odometry);
};  

Then, in an associated .cpp file, I started defining the body of class stage_listener:

#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 "tf/transform_listener.h"

void 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(){}

Anyway, for what regads line

odom_node on;

I get the following error, after digiting make, once inside my ros package:

CMakeFiles/stage_listener.dir/src/stage_listener.o: In function `addOdomNode(nav_msgs::Odometry_<std::allocator<void> >)':
/home/ubisum/fuerte_workspace/beginner/src/stage_listener.cpp:18: undefined reference to `odom_node::odom_node()'
/home/ubisum/fuerte_workspace/beginner/src/stage_listener.cpp:18: undefined reference to `odom_node::~odom_node()'

Does anyone know the reason? I'm sorry if question may seem too silly, but I'm learning C++ and ROS at the once and it's not easy when coming from Java and MatLab.

Thanks for help

edit retag flag offensive close merge delete

Comments

How did you link .h and .cpp file?

Po-Jen Lai gravatar imagePo-Jen Lai ( 2012-11-18 05:41:25 -0600 )edit

how can i make ROS compiler see my header files? using rosbuild_add_executable(example examples/example.cpp) seems uncorrect, since my cpp file associated to the header have no main can i use any of the expression in CMakeLists just to make .h headers visible?

ubisum gravatar imageubisum ( 2012-11-19 22:43:23 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-11-18 09:01:20 -0600

Lorenz gravatar image

There are a bunch of problems with your code. The problem you are referring to is probably caused by missing cpp files in your target in CMakeLists.txt. The linker just cannot find the implementation of odom_node's constructor.

I guess you are trying to implement the method addOdomNode in class stage_listener. However, you are creating a function in the global namespace (you need to write stage_listener::addOdomNode in your cpp file). And you shouldn't put several classes in one header file. Instead, create one .h and one .cpp file per class.

I would also not suggest to implement linked lists manually. The C++ STL already provides many container classes, including doubly-linked lists and vectors.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-11-18 01:19:24 -0600

Seen: 204 times

Last updated: Nov 19 '12