c++ - ROS rosmake error -
i working on project ros. new ros , it's features. i'm doing tutorial on ros , started using code first time. although have experience c++, can't figure out going wrong. in ros use rosmake command , fails compile cpp file/code. can me figure out why error occurs? (and possibly how fix it?)
below cpp file code:
#include "ros/ros.h" #include "std_msgs/string.h" #include <sstream> int main(int argc, char **argv) { ros::init(argc, argv, "example1_a"); ros::nodehandle n; ros::publisher chatter_pub = n.advertise<std_ msgs::string>("message", 1000); ros::rate loop_rate(10); while (ros::ok()) { std_msgs::string msg; std::stringstream ss; ss << " example1_a node "; msg.data = ss.str(); //ros_info("%s", msg.data.c_str()); chatter_pub.publish(msg); ros::spinonce(); loop_rate.sleep(); } return 0; }
and here build log:
mkdir -p bin cd build && cmake -wdev -dcmake_toolchain_file=/opt/ros/indigo/share/ros/core/rosbuild/rostoolchain.cmake .. [rosbuild] building package chapter2_tutorials [rosbuild] using multiarch 'x86_64-linux-gnu' finding boost -- using catkin_devel_prefix: /home/rospc/dev/rosbook/chapter2_tutorials/build/devel -- using cmake_prefix_path: /opt/ros/indigo -- workspace overlays: /opt/ros/indigo -- using python_executable: /usr/bin/python -- using debian python package layout -- using empy: /usr/bin/empy -- using catkin_enable_testing: on -- skip enable_testing() dry packages -- using catkin_test_results_dir: /home/rospc/dev/rosbook/chapter2_tutorials/build/test_results -- found gtest sources under '/usr/src/gtest': gtests built -- using python nosetests: /usr/bin/nosetests-2.7 -- catkin 0.6.16 -- using these message generators: gencpp;genlisp;genpy [rosbuild] including /opt/ros/indigo/share/roslisp/rosbuild/roslisp.cmake [rosbuild] including /opt/ros/indigo/share/roscpp/rosbuild/roscpp.cmake [rosbuild] including /opt/ros/indigo/share/rospy/rosbuild/rospy.cmake -- configuring done -- generating done -- build files have been written to: /home/rospc/dev/rosbook/chapter2_tutorials/build cd build && make -j8 -l8 make[1]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[2]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' [ 0%] built target rospack_genmsg_libexe make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' [ 0%] built target rosbuild_precompile make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' scanning dependencies of target example1_a scanning dependencies of target example1_b make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[3]: entering directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' [100%] [100%] building cxx object cmakefiles/example1_b.dir/src/example1_b.cpp.o building cxx object cmakefiles/example1_a.dir/src/example1_a.cpp.o /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp: in function ‘int main(int, char**)’: /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:42: error: ‘std_’ not declared in scope ros::publisher chatter_pub = n.advertise<std_ ^ /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:8:32: error: parse error in template argument list ros::publisher chatter_pub = n.advertise<std_ ^ /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: no matching function call ‘ros::nodehandle::advertise(const char [8], int)’ msgs::string>("message", 1000); ^ /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: note: candidates are: in file included /opt/ros/indigo/include/ros/ros.h:45:0, /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1: /opt/ros/indigo/include/ros/node_handle.h:236:15: note: template<class m> ros::publisher ros::nodehandle::advertise(const string&, uint32_t, bool) publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false) ^ /opt/ros/indigo/include/ros/node_handle.h:236:15: note: template argument deduction/substitution failed: /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 invalid msgs::string>("message", 1000); ^ in file included /opt/ros/indigo/include/ros/ros.h:45:0, /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:1: /opt/ros/indigo/include/ros/node_handle.h:302:13: note: template<class m> ros::publisher ros::nodehandle::advertise(const string&, uint32_t, const subscriberstatuscallback&, const subscriberstatuscallback&, const voidconstptr&, bool) publisher advertise(const std::string& topic, uint32_t queue_size, ^ /opt/ros/indigo/include/ros/node_handle.h:302:13: note: template argument deduction/substitution failed: /home/rospc/dev/rosbook/chapter2_tutorials/src/example1_a.cpp:9:30: error: template argument 1 invalid msgs::string>("message", 1000); ^ make[3]: *** [cmakefiles/example1_a.dir/src/example1_a.cpp.o] error 1 make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[2]: *** [cmakefiles/example1_a.dir/all] error 2 make[2]: *** waiting unfinished jobs.... linking cxx executable ../bin/example1_b make[3]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' [100%] built target example1_b make[2]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make[1]: *** [all] error 2 make[1]: leaving directory `/home/rospc/dev/rosbook/chapter2_tutorials/build' make: *** [all] error 2
this next code second file, compile , creates no errors:
#include "ros/ros.h" #include "std_msgs/string.h" void chattercallback(const std_msgs::string::constptr& msg) { ros_info("i heard: [%s]", msg->data.c_str()); } int main(int argc, char **argv) { ros::init(argc, argv, "example1_b"); ros::nodehandle n; ros::subscriber sub = n.subscribe("message", 1000, chattercallback); ros::spin(); return 0; }
line breaks in c++ code can done in 3 ways :
cout<<"error:this long error " "message exceeds maximum permitted length.\n";
or
cout<<"error:this long error \ message exceeds maximum permitted length.\n";
or
c\ o\ u\ t<<"error:this long error \ message exceeds maximum permitted length.\n";
other that, throw errors ...
Comments
Post a Comment