{
  "id": "cmake/cross-compiling-toolchain-cmake-variable-not-set",
  "signature": "CMake Error: CMAKE_CROSSCOMPILING is TRUE but CMAKE_SYSTEM_NAME is not set.",
  "signature_zh": "CMake 错误：CMAKE_CROSSCOMPILING 为 TRUE，但未设置 CMAKE_SYSTEM_NAME。",
  "regex": "CMAKE_CROSSCOMPILING is TRUE but CMAKE_SYSTEM_NAME is not set",
  "domain": "cmake",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "When cross-compiling, CMake requires CMAKE_SYSTEM_NAME to be set in the toolchain file or command line; otherwise, it defaults to the host system, causing a mismatch.",
  "root_cause_type": "generic",
  "root_cause_zh": "在进行交叉编译时，CMake 需要在工具链文件或命令行中设置 CMAKE_SYSTEM_NAME，否则默认为主机系统，导致不匹配。",
  "versions": [
    {
      "version": "cmake 3.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cmake 3.25",
      "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Setting CMAKE_CROSSCOMPILING to FALSE manually in CMakeLists.txt",
      "why_fails": "Overriding CMAKE_CROSSCOMPILING is a read-only variable; CMake ignores user attempts to set it.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding set(CMAKE_SYSTEM_NAME Linux) in CMakeLists.txt instead of toolchain file",
      "why_fails": "CMAKE_SYSTEM_NAME must be set before the project() call; CMakeLists.txt executes after, so it has no effect.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Define CMAKE_SYSTEM_NAME in your toolchain file, e.g., set(CMAKE_SYSTEM_NAME Linux). Then pass the toolchain file via -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake.",
      "success_rate": 0.85,
      "how": "Define CMAKE_SYSTEM_NAME in your toolchain file, e.g., set(CMAKE_SYSTEM_NAME Linux). Then pass the toolchain file via -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..",
      "success_rate": 0.8,
      "how": "Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在工具链文件中设置 CMAKE_SYSTEM_NAME，例如 set(CMAKE_SYSTEM_NAME Linux)。然后通过 -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake 传递工具链文件。",
    "或者在命令行中设置 CMAKE_SYSTEM_NAME：cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc .."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2023-04-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}