cmake
config_error
ai_generated
true
CMake Error: CMAKE_CROSSCOMPILING is TRUE but CMAKE_SYSTEM_NAME is not set.
ID: cmake/cross-compiling-toolchain-cmake-variable-not-set
82%Fix Rate
85%Confidence
1Evidence
2023-04-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| cmake 3.22 | active | — | — | — |
| cmake 3.25 | active | — | — | — |
| cmake 3.28 | active | — | — | — |
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.
generic中文
在进行交叉编译时,CMake 需要在工具链文件或命令行中设置 CMAKE_SYSTEM_NAME,否则默认为主机系统,导致不匹配。
Official Documentation
https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compilingWorkarounds
-
85% success 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.
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.
-
80% success Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..
Alternatively, set CMAKE_SYSTEM_NAME on the command line: cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..
中文步骤
在工具链文件中设置 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 ..
Dead Ends
Common approaches that don't work:
-
Setting CMAKE_CROSSCOMPILING to FALSE manually in CMakeLists.txt
95% fail
Overriding CMAKE_CROSSCOMPILING is a read-only variable; CMake ignores user attempts to set it.
-
Adding set(CMAKE_SYSTEM_NAME Linux) in CMakeLists.txt instead of toolchain file
90% fail
CMAKE_SYSTEM_NAME must be set before the project() call; CMakeLists.txt executes after, so it has no effect.