{
  "id": "go/cgo-multiple-definition-symbol",
  "signature": "ld: symbol 'foo' has multiple definitions (from object files a.o and b.o)",
  "signature_zh": "ld：符号 'foo' 有多个定义（来自目标文件 a.o 和 b.o）",
  "regex": "ld: symbol '.*' has multiple definitions",
  "domain": "go",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "Duplicate symbol definitions across C object files linked via cgo, often due to including the same .c file in multiple packages or using static libraries with conflicting symbols.",
  "root_cause_type": "generic",
  "root_cause_zh": "通过 cgo 链接的 C 目标文件之间存在重复符号定义，通常是由于在多个包中包含相同的 .c 文件或使用具有冲突符号的静态库。",
  "versions": [
    {
      "version": "Go 1.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This flag suppresses the error but can cause undefined behavior or crashes due to symbol aliasing.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the duplicate comes from a static library you don't control, renaming isn't possible.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Multiple definitions occur at link time from different .o files, not from header inclusion; pragma doesn't help.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure each .c file is compiled only once by consolidating cgo directives into a single package or using a single .go file with all C code",
      "success_rate": 0.85,
      "how": "Ensure each .c file is compiled only once by consolidating cgo directives into a single package or using a single .go file with all C code",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use linker flag -Wl,--allow-multiple-definition to force link but verify behavior",
      "success_rate": 0.7,
      "how": "Use linker flag -Wl,--allow-multiple-definition to force link but verify behavior",
      "condition": "",
      "sources": []
    },
    {
      "action": "Refactor to avoid static libraries with overlapping symbols; use dynamic linking or rename symbols via objcopy",
      "success_rate": 0.8,
      "how": "Refactor to avoid static libraries with overlapping symbols; use dynamic linking or rename symbols via objcopy",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure each .c file is compiled only once by consolidating cgo directives into a single package or using a single .go file with all C code",
    "Use linker flag -Wl,--allow-multiple-definition to force link but verify behavior",
    "Refactor to avoid static libraries with overlapping symbols; use dynamic linking or rename symbols via objcopy"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://pkg.go.dev/cmd/cgo",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.75,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}