{
  "id": "cmake/abi-mismatch-pic",
  "signature": "CMake Error: Target 'mylib' requires PIC mode but its dependency 'otherlib' is built without PIC. Reconfigure otherlib with CMAKE_POSITION_INDEPENDENT_CODE=ON.",
  "signature_zh": "CMake 错误：目标 'mylib' 要求 PIC 模式，但其依赖 'otherlib' 未使用 PIC 构建。请使用 CMAKE_POSITION_INDEPENDENT_CODE=ON 重新配置 otherlib。",
  "regex": "Target '[^']+' requires PIC mode but its dependency '[^']+' is built without PIC",
  "domain": "cmake",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "A shared library target requires position-independent code (PIC), but a static library dependency was built without PIC, causing linker errors or ABI incompatibility.",
  "root_cause_type": "generic",
  "root_cause_zh": "共享库目标需要位置无关代码 (PIC)，但静态库依赖项未使用 PIC 构建，导致链接错误或 ABI 不兼容。",
  "versions": [
    {
      "version": "CMake 3.10+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "GCC 9.3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Add -fPIC manually to target_compile_options for otherlib",
      "why_fails": "CMake's PIC handling is more nuanced; manual flags may conflict with CMake's own POSITION_INDEPENDENT_CODE property.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Set CMAKE_POSITION_INDEPENDENT_CODE globally to ON",
      "why_fails": "Forces PIC on all targets, which may break performance on some architectures (e.g., x86-64) and is not always desired.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Change mylib to STATIC library to avoid PIC requirement",
      "why_fails": "If mylib must be shared (e.g., for plugin loading), this changes the library type and may break downstream consumers.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set PIC on the dependency target explicitly: set_target_properties(otherlib PROPERTIES POSITION_INDEPENDENT_CODE ON). Then reconfigure.",
      "success_rate": 0.95,
      "how": "Set PIC on the dependency target explicitly: set_target_properties(otherlib PROPERTIES POSITION_INDEPENDENT_CODE ON). Then reconfigure.",
      "condition": "",
      "sources": []
    },
    {
      "action": "In CMakeLists.txt, before add_library for otherlib, set: set(CMAKE_POSITION_INDEPENDENT_CODE ON). This ensures all subsequent static libraries are built with PIC.",
      "success_rate": 0.9,
      "how": "In CMakeLists.txt, before add_library for otherlib, set: set(CMAKE_POSITION_INDEPENDENT_CODE ON). This ensures all subsequent static libraries are built with PIC.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If otherlib is an external package, rebuild it with -DCMAKE_POSITION_INDEPENDENT_CODE=ON flag during its own CMake configure step.",
      "success_rate": 0.85,
      "how": "If otherlib is an external package, rebuild it with -DCMAKE_POSITION_INDEPENDENT_CODE=ON flag during its own CMake configure step.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在依赖目标上显式设置 PIC：set_target_properties(otherlib PROPERTIES POSITION_INDEPENDENT_CODE ON)。然后重新配置。",
    "在 CMakeLists.txt 中，在 add_library 为 otherlib 之前设置：set(CMAKE_POSITION_INDEPENDENT_CODE ON)。确保后续所有静态库都使用 PIC 构建。",
    "如果 otherlib 是外部包，在其自己的 CMake 配置步骤中使用 -DCMAKE_POSITION_INDEPENDENT_CODE=ON 重新构建。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}