[ros-users] C++ compiling problem with ROS
Tim Field
tfield at willowgarage.com
Mon May 31 18:17:44 UTC 2010
You've a missing > on line 15 of add_two_ints_client.cpp.
On Mon, May 31, 2010 at 11:08 AM, ibwood <ianbenjiman at hotmail.com> wrote:
>
> Hi all,
>
> I am trying to compile some C++ code with ROS, examining a service and
> client. Before attempting to run the service, I tried to 'make' the stack
> with the two source codes in it. Here is the code and the output of the
> command:
>
> $ roscd beginner_tutorials
> $ make
> mkdir -p bin
> cd build && cmake -Wdev -DCMAKE_TOOLCHAIN_FILE=`rospack find
> rosbuild`/rostoolchain.cmake ..
> [rosbuild] Building package beginner_tutorials
> [rosbuild] Including /home/ian/ros/ros/core/rospy/cmake/rospy.cmake
> [rosbuild] Including /home/ian/ros/ros/core/roscpp/cmake/roscpp.cmake
> -- Configuring done
> -- Generating done
> -- Build files have been written to:
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/build
> cd build && make
> make[1]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[2]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[3]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[3]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> [ 0%] Built target rospack_genmsg_libexe
> make[3]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[3]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> [ 0%] Built target rosbuild_precompile
> make[3]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[3]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[3]: Entering directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> [ 50%] Building CXX object
> CMakeFiles/add_two_ints_client.dir/src/add_two_ints_client.o
>
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/add_two_ints_client.cpp:
> In function ‘int main(int, char**)’:
>
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/add_two_ints_client.cpp:15:
> error: no matching function for call to
> ‘beginner_tutorials::AddTwoInts::AddTwoInts(const char [13])’
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/AddTwoInts.h:16:
> note: candidates are: beginner_tutorials::AddTwoInts::AddTwoInts()
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/AddTwoInts.h:16:
> note: beginner_tutorials::AddTwoInts::AddTwoInts(const
> beginner_tutorials::AddTwoInts&)
>
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/add_two_ints_client.cpp:15:
> error: parse error in template argument list
>
> /home/ian/ros/ros/ros_tutorials/beginner_tutorials/src/add_two_ints_client.cpp:15:
> error: conversion from ‘<unresolved overloaded function type>’ to
> non-scalar
> type ‘ros::ServiceClient’ requested
> make[3]: *** [CMakeFiles/add_two_ints_client.dir/src/add_two_ints_client.o]
> Error 1
> make[3]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[2]: *** [CMakeFiles/add_two_ints_client.dir/all] Error 2
> make[2]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make[1]: *** [all] Error 2
> make[1]: Leaving directory
> `/home/ian/ros/ros/ros_tutorials/beginner_tutorials/build'
> make: *** [all] Error 2
>
>
>
> my source files are in an "src" package located in the "beginner_tutorials"
> package, and my header files are located in the same folder as the cpp
> source files.. Here are the two programs:
>
> ------------------------------------
> add_two_ints_server.cpp
> ------------------------------------
> #include "ros.h"
> #include "AddTwoInts.h"
>
> bool add(beginner_tutorials::AddTwoInts::Request &req,
> beginner_tutorials::AddTwoInts::Response &res )
> {
> res.sum = req.a + req.b;
> ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
> ROS_INFO("sending back response: [%ld]", (long int)res.sum);
> return true;
> }
>
> int main(int argc, char **argv)
> {
> ros::init(argc, argv, "add_two_ints_server");
> ros::NodeHandle n;
>
> ros::ServiceServer service = n.advertiseService("add_two_ints", add);
> ROS_INFO("Ready to add two ints.");
> ros::spin();
>
> return 0;
> }
>
>
> -------------------------------------
> add_two_ints_client.cpp
> -------------------------------------
> #include "ros.h"
> #include "AddTwoInts.h"
> #include <cstdlib>
>
> int main(int argc, char **argv)
> {
> ros::init(argc, argv, "add_two_ints_client");
> if (argc != 3)
> {
> ROS_INFO("usage: add_two_ints_client X Y");
> return 1;
> }
>
> ros::NodeHandle n;
> ros::ServiceClient client =
> n.serviceClient<beginner_tutorials::AddTwoInts("add_two_ints");
> beginner_tutorials::AddTwoInts srv;
> srv.request.a = atoll(argv[1]);
> srv.request.b = atoll(argv[2]);
> if (client.call(srv))
> {
> ROS_INFO("Sum: %ld", (long int)srv.response.sum);
> }
> else
> {
> ROS_ERROR("Failed to call service add_two_ints");
> return 1;
> }
>
> return 0;
> }
>
>
> I added these two lines to CMakeLists.txt (located in the
> beginner_tutorials
> package) as well:
> rosbuild_add_executable(add_two_ints_server src/add_two_ints_server.cpp)
> rosbuild_add_executable(add_two_ints_client src/add_two_ints_client.cpp)
>
>
> I have been trying to figure out what is wrong with the compiler. So the
> question is.. where did I go wrong? Thanks in advance for any help and/or
> direction.
>
> -Ian
> --
> View this message in context:
> http://ros-users.122217.n3.nabble.com/C-compiling-problem-with-ROS-tp859217p859217.html
> Sent from the ROS-Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> ros-users mailing list
> ros-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ros-users
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20100531/4e401b2e/attachment-0003.html>
More information about the ros-users
mailing list