Ask Your Question

I am not able to run a node. [closed]

asked 2019-12-01 11:04:44 -0500

ammaralam221 gravatar image

I am running ros kinetic on ubuntu 16.

While running a file hello_world.cpp, I get the following error

/media/ammar/New Volume/December/ros_directory/src/agitr_book/src/hello_world.cpp: line 2: syntax error near unexpected token `('
/media/ammar/New Volume/December/ros_directory/src/agitr_book/src/hello_world.cpp: line 2: `int main (int argc, char **argv)'

This is the code in hello_world.cpp

#include "ros/ros.h"
int main (int argc, char **argv)
    //intializes ros client library
    //last parameter is a string containing
    //deafult name of the node
    //can be overwridden by a launch file
    //call this once at the beginning of the program
    ros::init(argc, argv, "hello_ros");

    //establishes this program as a ros node
    //nh is the main mechanism that the program
    //will use to interact with the ROS system
    //creating this object registers the program
    //as a node at ros master
    ros::NodeHandle nh;

    //generates an informational message
    //send to console screen

I don't think, there is anything wrong the code as I am following it along with a book. I believe the problem is with the #include line but i don't know what?? If anyone could help me, it will be appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ammaralam221
close date 2019-12-02 05:36:11.056769


Since your node is C++, you need to compile it before you run it.

ahendrix gravatar image ahendrix  ( 2019-12-01 12:32:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-01 12:24:47 -0500

I ran your code and found no issues... (ubuntu 16.04 with ROS kinetic), however you are not publishing your CMakeLists.txt neither your package.xml files. Here are mine for reference:


cmake_minimum_required(VERSION 2.8.3)

## Compile as C++11, supported in ROS Kinetic and newer

find_package(catkin REQUIRED


add_executable(hello_world ros/src/hello_world.cpp)
target_link_libraries(hello_world ${catkin_LIBRARIES})


<?xml version="1.0"?>
    hello world tutorial


<author email="">Oscar Lima</author>
<maintainer email="">Oscar Lima</maintainer>




Compile your code

catkin build --this

Very important: source your workspace again after having compiled

source ~/my_catkin_ws/devel/setup.bash

Run the code

rosrun hello_world hello_world

You should now be able to see the desired output

[ INFO] [/hello_ros]: HELLO_ROS
edit flag offensive delete link more


Thanks for your help. I found what I was doing wrong, there was a problem with the rosrun command I was using

rosrun agitr_book hello_world.cpp

there shouldn't be a .cpp in this, the correct command is

rosrun agitr_book hello_world
ammaralam221 gravatar image ammaralam221  ( 2019-12-02 05:35:40 -0500 )edit

Question Tools


Asked: 2019-12-01 11:04:44 -0500

Seen: 141 times

Last updated: Dec 01 '19