{
  "id": "cmake/export-library-path-mismatch",
  "signature": "CMake Error: install(EXPORT) generated target \"mylib\" but target \"mylib\" has library output path \"/build/lib\" that does not match the install destination \"/usr/local/lib\"",
  "signature_zh": "CMake 错误：install(EXPORT) 生成了目标 \"mylib\"，但目标 \"mylib\" 的库输出路径 \"/build/lib\" 与安装目标 \"/usr/local/lib\" 不匹配",
  "regex": "CMake Error: install\\(EXPORT\\) generated target \"[^\"]+\" but target \"[^\"]+\" has library output path \"[^\"]+\" that does not match the install destination \"[^\"]+\"",
  "domain": "cmake",
  "category": "install_error",
  "subcategory": null,
  "root_cause": "The target's LIBRARY_OUTPUT_DIRECTORY or ARCHIVE_OUTPUT_DIRECTORY differs from the DESTINATION specified in install(TARGETS), causing CMake to detect a mismatch during export generation.",
  "root_cause_type": "generic",
  "root_cause_zh": "目标的 LIBRARY_OUTPUT_DIRECTORY 或 ARCHIVE_OUTPUT_DIRECTORY 与 install(TARGETS) 中指定的 DESTINATION 不同，导致 CMake 在生成导出时检测到不匹配。",
  "versions": [
    {
      "version": "cmake 3.26.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake 3.27.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake 3.28.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Change LIBRARY_OUTPUT_DIRECTORY to match the install destination",
      "why_fails": "LIBRARY_OUTPUT_DIRECTORY affects build-time output, not install; changing it may break build scripts or tests that expect the library in the original build directory.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove install(EXPORT) entirely",
      "why_fails": "Removes the export mechanism, so downstream projects using find_package will fail to locate the package.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set the target's output directory to match the install destination using generator expressions:\n\nset_target_properties(mylib PROPERTIES\n  LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n  ARCHIVE_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n)\n\nThen ensure install(TARGETS mylib DESTINATION lib) matches.",
      "success_rate": 0.9,
      "how": "Set the target's output directory to match the install destination using generator expressions:\n\nset_target_properties(mylib PROPERTIES\n  LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n  ARCHIVE_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n)\n\nThen ensure install(TARGETS mylib DESTINATION lib) matches.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a relative path in install(DESTINATION) that matches the build output:\n\nset_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/lib\")\ninstall(TARGETS mylib DESTINATION \"${CMAKE_BINARY_DIR}/lib\")\n\nThen generate the export with install(EXPORT ... DESTINATION \"${CMAKE_BINARY_DIR}/lib\")",
      "success_rate": 0.85,
      "how": "Use a relative path in install(DESTINATION) that matches the build output:\n\nset_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/lib\")\ninstall(TARGETS mylib DESTINATION \"${CMAKE_BINARY_DIR}/lib\")\n\nThen generate the export with install(EXPORT ... DESTINATION \"${CMAKE_BINARY_DIR}/lib\")",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用生成器表达式将目标的输出目录设置为与安装目标匹配：\n\nset_target_properties(mylib PROPERTIES\n  LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n  ARCHIVE_OUTPUT_DIRECTORY \"${CMAKE_INSTALL_PREFIX}/lib\"\n)\n\n然后确保 install(TARGETS mylib DESTINATION lib) 匹配。",
    "使用与构建输出匹配的 install(DESTINATION) 相对路径：\n\nset_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY \"${CMAKE_BINARY_DIR}/lib\")\ninstall(TARGETS mylib DESTINATION \"${CMAKE_BINARY_DIR}/lib\")\n\n然后使用 install(EXPORT ... DESTINATION \"${CMAKE_BINARY_DIR}/lib\") 生成导出。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/command/install.html#exporting-targets",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}