# Simple Service and Client Tutorial Problem [closed]

I am going through the tutorial with ROS, and its been fairly smooth so far. However, I just got to the section on creating a simple service and client in c++, and regardless of what I do, I keep running into errors when making add_two_ints_client.cpp and add_two_ints_server.cpp. They both call on a header file called AddTwoInts.h, however the tutorial never went over what that was. To compensate for that, I went and grabbed the TwoInts.h header file from the roscpp_tutorials package. At first I put it under beginners_tutorials like the example suggested, but I received a message stating beginner_tutorials was not declared in this scope. I did, however, get the code to accept TwoInts.h by just throwing it in src with the rest of the code and just calling

#include "TwoInts.h"


With that out of the way, I now receive an additional error down the line when I go to use TwoInts. I go to call

ros::ServiceClient client = n.serviceClient<TwoInts>("add_two_ints");


but the compiler says it doesn't know what TwoInts is. I then tried beginner_tutorials::TwoInts, then TwoInts::TwoInts, and even roscpp::TwoInts, but each time, it could not make.

My code looks almost identical to the sample code (aside from it being in a different location). I keep going back to past tutorials hoping to find something that mentions TwoInts.h, but if its there, I can't find it.

Has anyone run into this? How am I supposed to solve this?

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Wim close date 2011-08-02 11:26:30

Sort by » oldest newest most voted

At the top of the tutorial, in section 1.1, it says to make sure to build on two completed tutorials:

I suspect that using those will resolve your issue.

more

Well, I have finally managed to get the example to build. To do so:

1. copy the TwoInts.h file from roscpp_tutorials to the include folder of your tutorial project.
2. rename the namespace for the TwoInts.h file to your project name and go through and change every recurrance. i.e. since my project was under beginner_tutorials, change every roscpp_tutorials::TwoInt to beginner_tutorials::TwoInt
3. in your add_two_ints_server.cpp and add_two_ints_client.cpp files, make sure the include refers to where you put the TwoInts.h (also, make sure its not 'AddTwoInts.h' like the tutorial)
4. When you go to use TwoInts in your client and server file, make sure it refers to your namespace (for me it was beginner_tutorials::TwoInt).
more