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

Error when trying to run a ros node

asked 2022-02-03 08:03:33 -0500

princesalasi gravatar image

updated 2022-02-03 09:39:34 -0500

gvdhoorn gravatar image

I have this example ros publisher I have created for debugging purpose. It builds withouth any problem but when i rosrun the ros code, I get these errors and I dont where its coming from and why my publisher does not work. I will be happy with anyone who can help me. I used catkin clean to clean everything and build it again but it still did not work out.

**/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 6: /bin: Is a directory
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 7: build: command not found
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 8: build/: Is a directory
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 9: syntax error near unexpected token `('
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.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, "port_publisher_node");

  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; = ss.str();





  return 0;
edit retag flag offensive close merge delete


It would be good if you could tell us in the question the exact commands used to compile and to run your executable. Also, check the content of the file (maybe you are running a bash script that has the same file of the executable).

Ruben Alves gravatar image Ruben Alves  ( 2022-02-03 08:38:47 -0500 )edit

I used catkin build the build my package. And then use rosrun hfrimu port_publisher.cpp to run the node. If you say I should check the content, which cotent are you talking about please?

princesalasi gravatar image princesalasi  ( 2022-02-03 08:45:46 -0500 )edit

Try rosrun port_publisher_node from inside from the same directory as the source code.

skpro19 gravatar image skpro19  ( 2022-02-03 11:03:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-02-03 09:40:16 -0500

gvdhoorn gravatar image

You cannot directly run a .cpp file.

You can only execute the resulting binary.

The errors you show are caused by trying to execute the port_publisher.cpp file. C++ is not Python.

edit flag offensive delete link more


Yes, you are right. Instead of the node, I was specifying the file. rosrun hfrimu port_publisher_node worked for me.

princesalasi gravatar image princesalasi  ( 2022-02-03 11:43:45 -0500 )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: 2022-02-03 08:03:33 -0500

Seen: 33 times

Last updated: Feb 03