# 添加源文件,生成静态库 add_library(my_math_lib SHARD include/my_math_lib/my_math_lib.hpp src/my_math_lib.cpp ) # (不推荐)或者添加源文件,生成静态库 add_library(my_math_lib STATIC include/my_math_lib/my_math_lib.hpp src/my_math_lib.cpp ) # 用于代替传统的target_link_libraries ame...
在对add_library或add_executable的调用中,只有cpp文件被显式引用,并通过以下方式查找头文件, target_include_directories(my_target PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ) 2.3 添加依赖 有两种方法可以将包与新的依赖项链接起来。 方法1:ament_target_...
add.cpp定义了一个add()函数,如下: # include "add.h" int add(int a, int b){ return a+b; } 其中CMakeLists.txt中,除了ros2 pkg create lib_tut生成的默认内容外,在ament_package()前追加如下代码: include_directories(include/lib_tut) # 头文件 add_library(asdf src/add.cpp) # 库的名字...
add_library语句用于构建库。可以看到,上面使用了两个不同的语句来添加依赖。ament_target_dependencies是官方推荐的方式去添加依赖项。它将使依赖项的库、头文件和自身的依赖项被正常找到。 通常来说,若依赖项为ROS2功能包时,则使用ament_target_dependencies。若功能包有多个库,它也将一并包含。 target_link_libra...
add_library(talker_component SHARED src/talker_component.cpp) rclcpp_components_register_nodes(talker_component "composition::Talker") # To register multiple components in the same shared library, use multiple calls # rclcpp_components_register_nodes(talker_component "composition::Talker2") ...
add_library(action_server SHARED src/fibonacci_action_server.cpp) target_include_directories(action_server PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) target_compile_definitions(action_server PRIVATE "ACTION_TUTORIALS_CPP_BUILDING_DLL") ...
add_library(talker_component SHAREDsrc/talker_component.cpp)target_compile_definitions(talker_componentPRIVATE"COMPOSITION_BUILDING_DLL")ament_target_dependencies(talker_component"rclcpp""rclcpp_components""std_msgs")rclcpp_components_register_nodes(talker_component"composi...
add_library(polygon_plugins src/polygon_plugins.cpp) target_include_directories(polygon_plugins PUBLIC <BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> <INSTALL_INTERFACE:include>) ament_target_dependencies( polygon_plugins polygon_base pluginlib ...
find_package(rclcpp_components REQUIRED)add_library(radar_component SHARED src/radar_component.cpp src/utils.cpp src/crc64.cpp src/serial_port_base.cpp src/radar_24ghz4d_reader.cpp )target_compile_features(radar_component PUBLIC c_std_99 cxx_std_17) ...
(tf2_ros REQUIRED) find_package(geometry_msgs REQUIRED) find_package(sensor_msgs REQUIRED) find_package(visualization_msgs REQUIRED) set(dependencies rclcpp tf2_ros geometry_msgs sensor_msgs visualization_msgs ) include_directories(include) add_library(${PROJECT_NAME} SHARED src/br2_tf2_detector/...