catkin_make error when I follow wiki/Tutorials/WritingPublisherSubscriber

asked 2015-01-06 05:11:23 -0500

just_go gravatar image

updated 2015-01-07 04:06:00 -0500

gvdhoorn gravatar image

when I follow wiki Tutorials/WritingPublisherSubscriber(as follow): http://wiki.ros.org/cn/ROS/Tutorials/...

when I do "catkin_make" command in catkin_workspace , there happens some error (following:):

talker.cpp:(.text+0x56): **undefined reference** to `ros::init(int&, char**, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'

.....all the call from ros/ros.h are undefined. why ? how to solve this problem ?

I have added "target_link_libraries(listener ${catkin_LIBRARIES})"


include "ros/ros.h"
include "std_msgs/String.h"
include <sstream>

int main(int argc, char **argv){
    ros::init(argc, argv, "talker");
    ros::NodeHandle n;
    ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
    ros::Rate loop_rate(10);
    int count = 0;
    while (ros::ok()){
        std_msgs::String msg; std::stringstream ss; ss << "hello world " << count; msg.data = ss.str(); ROS_INFO("%s", msg.data.c_str());
    chatter_pub.publish(msg); ros::spinOnce(); loop_rate.sleep(); ++count; 
    }
    return 0;
}

who can help me to solve this problem?

edit retag flag offensive close merge delete

Comments

1

Can you post your cpp file as well as your cmake file?

tn0432 gravatar image tn0432  ( 2015-01-06 18:42:32 -0500 )edit

@just_go: please don't use answers to post updates to your questions. Edit your original question for that. I've updated your question with the contents of the answer you posted.

gvdhoorn gravatar image gvdhoorn  ( 2015-01-07 04:09:06 -0500 )edit