{
  "id": "ros2/ros2-ament-cmake-export-dependencies-missing",
  "signature": "CMake Error at CMakeLists.txt:25 (ament_target_dependencies): ament_target_dependencies() called with unknown target 'my_library'",
  "signature_zh": "CMake 错误在 CMakeLists.txt:25 (ament_target_dependencies)：ament_target_dependencies() 调用了未知的目标 'my_library'",
  "regex": "ament_target_dependencies\\(\\) called with unknown target '([^']+)'",
  "domain": "ros2",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "ament_target_dependencies() references a target that was not defined with add_library() or add_executable() before the call, typically due to missing or misordered CMake commands.",
  "root_cause_type": "generic",
  "root_cause_zh": "ament_target_dependencies() 引用了一个在调用前未通过 add_library() 或 add_executable() 定义的目标，通常由于缺少或顺序错误的 CMake 命令。",
  "versions": [
    {
      "version": "ros2:humble",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ros2:iron",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ament_cmake:1.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake:3.22.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding ament_target_dependencies before add_library in the same CMakeLists.txt",
      "why_fails": "The target must be defined before dependencies can be added; reordering does not fix the missing target definition.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Removing all ament_target_dependencies calls and using target_link_libraries directly",
      "why_fails": "This bypasses ament's dependency handling and may cause missing include paths or compile errors.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the target is defined before ament_target_dependencies. Example correct order:\nadd_library(my_library SHARED src/my_library.cpp)\nament_target_dependencies(my_library rclcpp std_msgs)\n\nIf the target is in a subdirectory, use add_subdirectory before referencing it.",
      "success_rate": 0.95,
      "how": "Ensure the target is defined before ament_target_dependencies. Example correct order:\nadd_library(my_library SHARED src/my_library.cpp)\nament_target_dependencies(my_library rclcpp std_msgs)\n\nIf the target is in a subdirectory, use add_subdirectory before referencing it.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the target is defined in another CMakeLists.txt via add_subdirectory, ensure the target name matches exactly. Verify with:\ncmake --build . --target my_library  # Check if target exists",
      "success_rate": 0.9,
      "how": "If the target is defined in another CMakeLists.txt via add_subdirectory, ensure the target name matches exactly. Verify with:\ncmake --build . --target my_library  # Check if target exists",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保在 ament_target_dependencies 之前定义目标。正确顺序示例：\nadd_library(my_library SHARED src/my_library.cpp)\nament_target_dependencies(my_library rclcpp std_msgs)\n\n如果目标在子目录中，请在引用前使用 add_subdirectory。",
    "如果目标通过 add_subdirectory 在另一个 CMakeLists.txt 中定义，请确保目标名称完全匹配。验证：\ncmake --build . --target my_library  # 检查目标是否存在"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.ros.org/en/humble/How-To-Guides/Ament-CMake-Documentation.html",
  "official_doc_section": null,
  "error_code": "ROS2-4001",
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-07-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}