error while building after adding a Subscriber node
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’
ok.
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::init(argc,argv,"subscriber");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("ardrone/navdata",Navdata,ReceiveData);
ros::spin();
return 0;
}
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
.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!