ros2 runtime_error ai_generated true

[component_container_isolated]: Failed to load component: Failed to find class with name 'my_pkg::MyComponent': No match

ID: ros2/component-container-isolated-failed-load

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-09-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
ROS 2 Humble active
ROS 2 Iron active
ROS 2 Rolling active

Root Cause

The component class is not registered with the component container; either the class export macro is missing or the package's plugin description XML is incorrect.

generic

中文

组件类未向组件容器注册;要么缺少类导出宏,要么包的插件描述 XML 不正确。

Official Documentation

https://docs.ros.org/en/humble/Tutorials/Intermediate/Composition.html

Workarounds

  1. 90% success Add the RCLCPP_COMPONENTS_REGISTER_NODE macro to your component source file: `RCLCPP_COMPONENTS_REGISTER_NODE(my_pkg::MyComponent)` and ensure the package.xml exports the plugin: `<export><build_type>ament_cmake</build_type><ros2_component plugin="${prefix}/my_plugins.xml"/></export>`
    Add the RCLCPP_COMPONENTS_REGISTER_NODE macro to your component source file: `RCLCPP_COMPONENTS_REGISTER_NODE(my_pkg::MyComponent)` and ensure the package.xml exports the plugin: `<export><build_type>ament_cmake</build_type><ros2_component plugin="${prefix}/my_plugins.xml"/></export>`
  2. 85% success Check the plugin description XML file (e.g., my_plugins.xml) for correct library path: `<library path="libmy_pkg_component"><class type="my_pkg::MyComponent" base_class_type="rclcpp::Node"/></library>`
    Check the plugin description XML file (e.g., my_plugins.xml) for correct library path: `<library path="libmy_pkg_component"><class type="my_pkg::MyComponent" base_class_type="rclcpp::Node"/></library>`
  3. 75% success Run `ros2 component types` to verify the component is registered; if not listed, the export is missing.
    Run `ros2 component types` to verify the component is registered; if not listed, the export is missing.

中文步骤

  1. 在组件源文件中添加 RCLCPP_COMPONENTS_REGISTER_NODE 宏:`RCLCPP_COMPONENTS_REGISTER_NODE(my_pkg::MyComponent)`,并确保 package.xml 导出插件:`<export><build_type>ament_cmake</build_type><ros2_component plugin="${prefix}/my_plugins.xml"/></export>`
  2. 检查插件描述 XML 文件(例如 my_plugins.xml)中的库路径是否正确:`<library path="libmy_pkg_component"><class type="my_pkg::MyComponent" base_class_type="rclcpp::Node"/></library>`
  3. 运行 `ros2 component types` 验证组件是否已注册;如果未列出,则导出缺失。

Dead Ends

Common approaches that don't work:

  1. Recompiling the package without cleaning build artifacts 40% fail

    The issue is in plugin registration, not compilation; rebuild doesn't fix missing exports.

  2. Manually copying the .so file to the container's library path 80% fail

    The container loads via pluginlib, not direct library loading; registration is required.

  3. Using component_container instead of component_container_isolated 60% fail

    Both containers use the same plugin registration mechanism; the error will persist.