Rosanswers logo

The same talker and listener works perfectly with a python file and why it fails to work with a cpp file.

rosrun ros_basic_tutorials talker.cpp 


/home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 6: /bin: Is a directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 7: listener.cpp: command not found /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 8: */: No such file or directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9: syntax error near unexpected token (' /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9: int main(int argc, char **argv)'


#include "ros/ros.h"
#include "std_msgs/String.h"

#include <sstream>

int main(int argc, char **argv)

  ros::init(argc, argv, "talker");

 ros::NodeHandle n;

  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

  ros::Rate loop_rate(10);

  int count = 0;
  while (ros::ok())
    std_msgs::String msg;

std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();

ROS_INFO("%s", msg.data.c_str());




  return 0;

Originally posted by ishaniis on ROS Answers with karma: 1 on 2020-03-22

Post score: 0


1 Answer 1


Rosanswers logo

you can't run a .cpp file.

The command should be

rosrun beginner_tutorials talker 

assuming you completed the section 3 Building your nodes of the WritingPublisherSubscriber(c++) tutorial

Originally posted by nickw with karma: 1504 on 2020-03-22

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by ishaniis on 2020-03-22:
Ahaan! Missing out on the important step. Thank you so much.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.