ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

error while building after adding a Subscriber node

asked 2014-09-05 14:02:48 -0600

voladoddi gravatar image

updated 2014-09-05 22:51:06 -0600

I created a subscriber node "Listener.cpp" in the src folder of the package ardrone_autonomy.

I also modified the CMakeLists.txt file by adding dependency, executable link However, when I go to my catkin workspace and type in "catkin_make",

It builds fine except for something wrong with my new file. What am I missing/ doing wrong?

ERROR shown below:

[100%] Building CXX object ardrone_autonomy/CMakeFiles/ardrone_driver.dir/src/listener.cpp.o
Linking CXX executable /home/voladoddi/catkin_ws/devel/lib/ardrone_autonomy/ardrone_driver
CMakeFiles/ardrone_driver.dir/src/listener.cpp.o: In function `main':
listener.cpp:(.text+0x152): multiple definition of `main'
CMakeFiles/ardrone_driver.dir/src/ardrone_driver.cpp.o:ardrone_driver.cpp:(.text+0x16a61): first defined here
/usr/bin/ld: cannot find -llistener
collect2: ld returned 1 exit status
make[2]: *** [/home/voladoddi/catkin_ws/devel/lib/ardrone_autonomy/ardrone_driver] Error 1
make[1]: *** [ardrone_autonomy/CMakeFiles/ardrone_driver.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

I checked the .cpp file I wrote. I cannot see any multiple definitions of main in the file. There's no other subscriber node named the same way either.

EDIT - As William pointed out, I was trying add the node to the executable of the existing package. However, I added two lines to the end of my Subscriber.cpp file like below:

#adding subscriber's node executable to the end of CMakeLists.txt file - POOJA
add_executable(subscriber src/subscriber.cpp)
target_link_libraries(subscriber ${catkin_LIBRARIES})

And now I'm getting the following errors:

 Build done.
Checking required Ubuntu packages ...
/home/voladoddi/catkin_ws/src/ardrone_autonomy/src/subscriber.cpp: In function ‘void ReceiveData(const ConstPtr&)’:
/home/voladoddi/catkin_ws/src/ardrone_autonomy/src/subscriber.cpp:8:2: error: ‘const struct ardrone_autonomy::Navdata_<std::allocator<void> >’ has no member named ‘data’
/home/voladoddi/catkin_ws/src/ardrone_autonomy/src/subscriber.cpp: In function ‘int main(int, char**)’:
/home/voladoddi/catkin_ws/src/ardrone_autonomy/src/subscriber.cpp:17:54: error: ‘Navdata’ was not declared in this scope
/home/voladoddi/catkin_ws/src/ardrone_autonomy/src/subscriber.cpp:17:54: note: suggested alternative:
/home/voladoddi/catkin_ws/devel/include/ardrone_autonomy/Navdata.h:246:61: note:   ‘ardrone_autonomy::Navdata’
Building ARDroneTool/Lib
make[2]: *** [ardrone_autonomy/CMakeFiles/subscriber.dir/src/subscriber.cpp.o] Error 1
make[1]: *** [ardrone_autonomy/CMakeFiles/subscriber.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Building ARDroneTool/Lib
[  4%] Performing install step for 'ardronelib'
make[3]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
[  5%] Completed 'ardronelib'
[  7%] Built target ardronelib
make: *** [all] Error 2

Here is my subscriber code:

#include "ros/ros.h"
#include "ardrone_autonomy/Navdata.h"

//The topics subscribed to : Time (from the header), Pitch angle(rotY)
// where the MESSAGE= ardrone_autonomy
void ReceiveData(const ardrone_autonomy::Navdata::ConstPtr& rot)
    ROS_INFO("Time: %d, Pitch angle: %d",rot->data.header.stamp.to_sec(),rot->rotY);

//instantiating subscriber
int main(int argc, char **argv)
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("ardrone/navdata",Navdata,ReceiveData);

    return 0;
edit retag flag offensive close merge delete


It looks like you are trying to link the new listener against the ardrone_autonomy executable, which doesn't really make sense. Please post your full CMakeLists.txt.

William gravatar image William  ( 2014-09-05 15:31:45 -0600 )edit

Hi... That was indeed the problem. However, after looking around, I've added it to the end of CMakeLists.txt .I'm getting some other errors.

Please do take a look and tell me what I'm doing wrong. I know it's got to do with variable names and scopes but if I get to know where to check,it'd help!

voladoddi gravatar image voladoddi  ( 2014-09-05 22:46:39 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2014-09-06 02:27:09 -0600

bvbdort gravatar image

Below Change in subscriber and add all the run and build dependencies in CMakeLists.txt and package.xml

ros::Subscriber sub = n.subscribe("ardrone/navdata",10,ReceiveData); //10 queue size
edit flag offensive delete link more


What changes do I need to make in the package.xml file?

voladoddi gravatar image voladoddi  ( 2014-09-09 11:25:30 -0600 )edit

Hi, thanks for the help. I can see that the subscribed messages are displayed when I subscribe to messages now. However, I don't understand what was wrong before.

"Navdata" is something that shouldn't be used for the queue name?

voladoddi gravatar image voladoddi  ( 2014-09-09 11:31:17 -0600 )edit

check the subscribe function arguments, (topicname,queuesize,callback). And for CMakeLists.txt and package.xml , i thought you may need to add dependencies but not required here. you can check more here

bvbdort gravatar image bvbdort  ( 2014-09-09 11:45:16 -0600 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-09-05 14:02:48 -0600

Seen: 816 times

Last updated: Sep 06 '14