0
$\begingroup$

Rosanswers logo

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_ >)':
/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


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

Post score: 0


Original comments

Comment by Po-Jen Lai on 2012-11-18:
How did you link .h and .cpp file?

Comment by ubisum on 2012-11-19:
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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


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

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

This site is temporarily in read-only mode and not accepting new answers.