0
$\begingroup$

Rosanswers logo

Just getting rosserial setup after a few days of issues. When trying to run the Hello World example (code below) I error out (also below). Any help would be great!

*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

// Use the following line if you have a Leonardo or MKR1000
//#define USE_USBCON

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(1000);
}

Error code

Arduino: 1.8.15 (Linux), Board: "Arduino Uno"

Hello_world:2:14: error: expected constructor, destructor, or type conversion before 'Publisher'
  * rosserial Publisher Example
              ^~~~~~~~~
exit status 1
expected constructor, destructor, or type conversion before 'Publisher'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Originally posted by matthewfwork on ROS Answers with karma: 15 on 2021-08-24

Post score: 0


Original comments

Comment by gvdhoorn on 2021-08-24:\

When trying to run the Hello World example

please, always link to whatever you are referring to.

We cannot see what you are seeing, so without a link, we have to spend time finding it ourselves, which means less time to help you solve your problem.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

If this is a verbatim copy-paste, you have this:

*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

Note how the first line starts with a *.

It's very likely you made a mistake copying the example, and it should actually be /*, which would be the start of a multi-line comment.

A single star (*) on its own is not a legal character there, hence the compiler error.


Originally posted by gvdhoorn with karma: 86574 on 2021-08-24

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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