1. 在名为beginner_tutorials的package包下的src文件夹下编写一个hello.cpp文件
#include<ros/ros.h>
int main(int argc,char **argv)
{
ros::init(argc,argv,"hello_ros");
ros::NodeHandle nh;
ROS_INFO("Hello_Ros!");
ros::spinOnce();
}
2. 修改CMakeList.txt文件
add_executable(hello /home/jianqiang/catkin_ws/src/beginner_tutorials/src/hello.cpp)
target_link_libraries(hello ${catkin_LIBRARIES})
add_executable(hello /home/jianqiang/catkin_ws/src/beginner_tutorials/src/hello.cpp)
要说明cpp文件再哪
接下来运行roscore, rosrun beginner_tutorials hello 即可