mkdir -p ws00_helloworld/src
cd ws00_helloworld/
colcon build
cd src/
ros2 pkg create pkg01_helloworld_cpp --build-type ament_cmake --dependencies rclcpp --node-name helloworld
cd ..
colcon build
. install/setup.bash
ros2 run pkg01_helloworld_cpp helloworld
#include <rclcpp/rclcpp.hpp>
int main(int argc, char ** argv)
{
rclcpp::init(argc,argv);
auto node = rclcpp::Node::make_shared("Helloworld_node");
RCLCPP_INFO(node->get_logger(),"hello_world!");
rclcpp::shutdown();
return 0;
}
注意:创建功能包在src目录
colcon build
. install/setup.bash
ros2 run pkg01_helloworld_cpp helloworld