From c4c8b320f6c590606aeda59686c28b9f2a6a5cd9 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Thu, 23 Jul 2026 08:32:18 +0200 Subject: [PATCH] arch/arm/cmake: Do not link an executable to detect the compiler. CMake validates a compiler by building and linking a test program. For a bare metal cross toolchain that link cannot succeed on its own terms, and the flags NuttX supplies for it assume a toolchain shipped with newlib: gcc.cmake sets set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs") A perfectly usable arm-none-eabi-gcc built without those specs therefore fails configuration before a single NuttX source file is considered: arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs': No such file or directory CMake Error: ... CMake will not be able to correctly generate this project. Setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY makes the detection step compile without linking, which is the documented approach for cross compiling to a bare metal target. Toolchains that do ship nosys.specs are unaffected: the flag only applies to CMake's own detection, not to the NuttX link. Assisted-by: Claude Code:claude-opus-4-8 Signed-off-by: Marco Casaroli --- arch/arm/src/cmake/Toolchain.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/arm/src/cmake/Toolchain.cmake b/arch/arm/src/cmake/Toolchain.cmake index cd3b2a630c97b..0559ba5def4df 100644 --- a/arch/arm/src/cmake/Toolchain.cmake +++ b/arch/arm/src/cmake/Toolchain.cmake @@ -25,6 +25,23 @@ set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_VERSION 1) +# Compiler detection must not try to link a full executable. +# +# CMake validates a compiler by building and linking a test program. For a bare +# metal cross toolchain that link cannot succeed on its own terms: it has no +# start files, no default linker script and no libc, and the flags NuttX +# supplies for it (CMAKE_EXE_LINKER_FLAGS_INIT below adds --specs=nosys.specs) +# assume a toolchain shipped with newlib. A perfectly usable arm-none-eabi-gcc +# without those specs then fails configuration before a single NuttX source file +# is considered: +# +# arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs' +# +# Building a static library instead exercises the compiler and stops short of +# the link, which is the documented approach for this case. + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + set(ARCH_SUBDIR) if(CONFIG_ARCH_ARMV7A) # ARMv7-A