Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error: redefinition of ‘ros::Subscriber<std_msgs::empty> sub

means you are violating the One Definition Rule (reusing the same name for a different object, with the same declaration as well) in these lines:

ros::Subscriber<std_msgs::Empty> sub("toggle_led1", &led1 );
ros::Subscriber<std_msgs::Empty> sub("toggle_led2", &led2 );
ros::Subscriber<std_msgs::Empty> sub("toggle_led3", &led3 );
ros::Subscriber<std_msgs::Empty> sub("toggle_all", &all );
ros::Subscriber<std_msgs::Empty> sub("toggle_light", &light );

so a simple solution would be to instead have

ros::Subscriber<std_msgs::Empty> sub_led1 ("toggle_led1", &led1);
ros::Subscriber<std_msgs::Empty> sub_led2 ("toggle_led2", &led2);
ros::Subscriber<std_msgs::Empty> sub_led3 ("toggle_led3", &led3);
ros::Subscriber<std_msgs::Empty> sub_all ("toggle_all", &all);
ros::Subscriber<std_msgs::Empty> sub_light ("toggle_light", &light);

This is not a ROS issue but a C++ one, you should check some C++ books and the Publisher Subscriber tutorial among the others.