{
  "id": "cmake/target-already-exists",
  "signature": "CMake Error: add_library cannot create target \"mylib\" because another target with the same name already exists.",
  "signature_zh": "CMake 错误：add_library 无法创建目标 \"mylib\"，因为已存在同名目标。",
  "regex": "CMake Error: add_(library|executable) cannot create target \".*?\" because another target with the same name already exists",
  "domain": "cmake",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "A target with the same name is defined twice in the same directory scope, typically due to duplicate add_library or add_executable calls, or a misspelled target name in a subdirectory.",
  "root_cause_type": "generic",
  "root_cause_zh": "在同一目录范围内重复定义了同名目标，通常是由于重复的 add_library 或 add_executable 调用，或子目录中目标名称拼写错误。",
  "versions": [
    {
      "version": "cmake 3.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake 3.28",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake 3.30",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The real cause is a duplicate definition; renaming may hide the issue but the original duplicate remains, causing other targets to reference the wrong one.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is in CMakeLists.txt logic, not cached state; clearing cache does not fix duplicate target definitions.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "target_compile_definitions does not create or rename targets; it only adds compile definitions to existing targets.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure each target has a unique name across all subdirectories. Use `add_library(mylib STATIC src/mylib.cpp)` only once. If needed, use `set_target_properties` to alias or create an INTERFACE library with a different name.",
      "success_rate": 0.85,
      "how": "Ensure each target has a unique name across all subdirectories. Use `add_library(mylib STATIC src/mylib.cpp)` only once. If needed, use `set_target_properties` to alias or create an INTERFACE library with a different name.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the duplicate is intentional (e.g., from FetchContent), wrap in `if(NOT TARGET mylib)` before definition:\nif(NOT TARGET mylib)\n  add_library(mylib STATIC src/mylib.cpp)\nendif()",
      "success_rate": 0.95,
      "how": "If the duplicate is intentional (e.g., from FetchContent), wrap in `if(NOT TARGET mylib)` before definition:\nif(NOT TARGET mylib)\n  add_library(mylib STATIC src/mylib.cpp)\nendif()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure each target has a unique name across all subdirectories. Use `add_library(mylib STATIC src/mylib.cpp)` only once. If needed, use `set_target_properties` to alias or create an INTERFACE library with a different name.",
    "If the duplicate is intentional (e.g., from FetchContent), wrap in `if(NOT TARGET mylib)` before definition:\nif(NOT TARGET mylib)\n  add_library(mylib STATIC src/mylib.cpp)\nendif()"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/command/add_library.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}