C++ Code compiling Issue in ROS
This post was updated on Mar 04, 2014; 1:26pm. Hi, I just started learning ROS and was able to build and run talker and listener example. After that I thought I should write a simple program to print "hello world" in the terminal.I wrote a hworld.cpp file shown below (I borrowed the template from talker.cpp) and I ran into problem while building the code. I am sorry if this kind of question has been asked before. I tried searching for it but I couldn't find it (I would be grateful if someone can link to an earlier similar question). Thank you in advance.
hworld.cpp
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv){
ros::init(argc, argv, "hworld");
ros::NodeHandle nh;
ros::Rate loop_rate(10);
int count =0;
while (ros::ok()){
cout<<"hello world"<<count<<endl;
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
Then I added this lines to the end of my CMakeList.txt file
add_executable(hwold src/hworld.cpp) target_link_libraries(hworld ${catkin_LIBRARIES}) add_dependencies(hworld beginner_tutorials_generate_messages_cpp)
but when I am running "catkin_make" I am getting the following error:
CMake Error at beginner_tutorials/CMakeLists.txt:176 (target_link_libraries): Cannot specify link libraries for target "hworld" which is not built by this project.
May be I am missing the concept behind building a code in roscpp??!!
Regards, TM