Skip to content

mock_components linked even when not specified in cmake, only linking controller_interface #2924

@Ewoodss

Description

@Ewoodss

Describe the bug
mock components is linked when only linking controller_interface.
this causes the following warning to be printed when loading the created controller.

Warning: class_loader.impl: SEVERE WARNING!!! A namespace collision has occurred with plugin factory for class mock_components::GenericSystem. New factory will OVERWRITE existing one. This situation occurs when libraries containing plugins are directly linked against an executable (the one running right now generating this message). Please separate plugins out into their own library or just don't link against the library and use either class_loader::ClassLoader/MultiLibraryClassLoader to open.
[ros2_control_node-1] at line 253 in /opt/ros/humble/include/class_loader/class_loader/class_loader_core.hpp

To Reproduce
Steps to reproduce the behavior:

  1. Create a custom controller
  2. in the cmake link against the controller_interface using modern cmake or ament_target_dependencies
  3. build with colcon --cmake-args --graphviz=graph.dot
  4. View the graph dot file using: dot -Tsvg test.dot -o graph.svg or open the .cmake/api/v1/reply/{target}.json and see that "fragment" : "/opt/ros/humble/lib/libmock_components.so" is listed

Expected behavior
no linking against mock_controllers when not specifying it.

Screenshots
cmake graphviz
Image

cmake api v1 reply json

{
	"fragment" : "/opt/ros/humble/lib/libmock_components.so",
	"role" : "libraries"
},

Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Version: humble
  • Linux tegra-ubuntu 5.15.148-tegra SMP PREEMPT aarch64 GNU/Linux

Additional context
example cmake

project(custom_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(THIS_PACKAGE_INCLUDE_DEPENDS
  controller_interface
  std_srvs
)

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(generate_parameter_library REQUIRED)

foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
  find_package(${Dependency} REQUIRED)
endforeach()

add_library(custom_controller SHARED
  src/custom_controller.cpp
)

generate_parameter_library(
  custom_controller_parameters  # cmake target name for the parameter library
  src/custom_controller.yaml # path to input yaml file
)

target_compile_features(custom_controller PUBLIC cxx_std_17)
target_include_directories(custom_controller PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/custom_controller>
)
target_link_libraries(custom_controller PRIVATE custom_controller_parameters)

target_link_libraries(custom_controller PUBLIC 
controller_interface::controller_interface
 ${std_srvs_TARGETS}
)

target_compile_definitions(custom_controller PRIVATE "CUSTOM_CONTROLLER_BUILDING_DLL")

pluginlib_export_plugin_description_file(controller_interface custom_controller.xml)


install(
  DIRECTORY include/
  DESTINATION include/custom_controller
)

install(TARGETS
    custom_controller custom_controller_parameters
  EXPORT export_custom_controller
  RUNTIME DESTINATION bin
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
)

ament_export_targets(export_custom_controller HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})

ament_package()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions