当前位置:网站首页>Ros2 pre basic tutorial | using cmakelists Txt compile ros2 node

Ros2 pre basic tutorial | using cmakelists Txt compile ros2 node

2022-06-22 15:14:00 Fish flavored ROS

The author of this series of tutorials : Little fish
official account : Fish fragrance ROS
QQ Communication group :139707339
Teaching video address : Small fish B standing
Full document address : Fish fragrance ROS Official website
Copyright notice : Reprint and commercial use are prohibited unless permitted .

Though through make call Makefile Compiling code is very convenient , But we still need to write by hand gcc Instructions to compile , Is there any way to automatically generate Makefile Well ?

The answer is yes , That's it cmake Tools .

cmake By calling CMakeLists.txt Directly generate Makefile.

1. install Cmake

sudo apt install cmake

2. newly build CMakeLists.txt

stay d2lros2/d2lros2/chapt2/basic newly build CMakeLists.txt, Type in the following .

cmake_minimum_required(VERSION 3.22)

project(first_node)

#include_directories  Add a specific header file search path  , It's equivalent to specifying g++ Compiler -I Parameters 
include_directories(/opt/ros/humble/include/rclcpp/)
include_directories(/opt/ros/humble/include/rcl/)
include_directories(/opt/ros/humble/include/rcutils/)
include_directories(/opt/ros/humble/include/rcl_yaml_param_parser/)
include_directories(/opt/ros/humble/include/rosidl_runtime_c/)
include_directories(/opt/ros/humble/include/rosidl_typesupport_interface/)
include_directories(/opt/ros/humble/include/rcpputils/)
include_directories(/opt/ros/humble/include/builtin_interfaces/)
include_directories(/opt/ros/humble/include/rmw/)
include_directories(/opt/ros/humble/include/rosidl_runtime_cpp/)
include_directories(/opt/ros/humble/include/tracetools/)
include_directories(/opt/ros/humble/include/rcl_interfaces/)
include_directories(/opt/ros/humble/include/libstatistics_collector/)
include_directories(/opt/ros/humble/include/statistics_msgs/)

# link_directories -  Add multiple specific library file search paths to the project , It's equivalent to specifying g++ Compiler -L Parameters 
link_directories(/opt/ros/humble/lib/)

# add_executable -  Generate first_node Executable file 
add_executable(first_node first_ros2_node.cpp)

# target_link_libraries -  by first_node( The goal is )  Add dynamic link library , Same as specified g++ compiler -l Parameters 
#  The following statement replaces  -lrclcpp -lrcutils
target_link_libraries(first_node rclcpp rcutils)

3. Compile code

We usually create a new directory , function cmake And compile , The advantage of this is that it won't seem so messy .

mkdir buildcd build

Create a folder , Then run cmake Instructions ,.. On behalf of the superior directory to find CMakeLists.txt.

cmake ..

Run out cmake You should be able to build See under directory cmake Automatically generated Makefile 了 , Then you can run make Instructions to compile

make

Run the above instructions , You can go to build Found in the directory first_node The node .

 picture

ROS2 Pre tutorial summary :

I exist because of us ,Ubuntu It also has philosophical significance

ROS2 Pre tutorial | Install... In a virtual machine Ubuntu

ROS2 Pre tutorial | Get along well with Ubuntu The common instructions of

ROS2 Pre tutorial | Get along well with Ubuntu Programming tools for

ROS2 Pre tutorial | Get along well with Ubuntu Common software

ROS2 Pre basic tutorial | Little fish teaches you to use g++ compile ROS2 node

ROS2 Pre basic tutorial | Little fish teaches you to use make compile ROS2 node

ROS2 Advanced tutorial summary :

ROS2 Advanced tutorial | ROS2 Anti counterfeiting of operating system of system architecture

原网站

版权声明
本文为[Fish flavored ROS]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221348261975.html