Unable to setup Zephyr Project with arm-none-eabi-gcc on MacOS

Hello,

I try to setup a project using Zephyr and a vanilla arm-none-eabli-gcc. I have one main repository containing a west.yml referencing github.com/.../sdk-nrf version v2.5.1 as the one and only west-project. sdk-nrf/west.yml is then pulling in a special Nordic version (v3.4.99-ncs1-1) of Zephyr (that's why I'm asking here, not at any Zephyr mailing list).

`west update` is working fine and also the Kconfig step does not yield any errors or warnings. Next, the provided compiler is tested and that fails. Zephyr seems to rely on a few functions provided by CMake and also seem to role their own Toolchain support. The following sequence of commands (executed from the build directory) results reproducible in an error:

rm -fr * 
rm  /Users/todi/Library/Caches/zephyr/ToolchainCapabilityDatabase/*
ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb GNUARMEMB_TOOLCHAIN_PATH=/usr/local/gcc-arm-none-eabi-8-2019-q3-update cmake --debug-trycompile -DCMAKE_REQUIRED_QUIET=0 ..

The `--debug-trycompile` and CMAKE_REQUIRED_QUITE was added by me, to debug the try_compile components of cmake. The output:

debug trycompile on
-- The C compiler identification is AppleClang 15.0.0.15000100
-- The CXX compiler identification is AppleClang 15.0.0.15000100
-- Detecting C compiler ABI info
CMake Debug Log at /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/CMakeDetermineCompilerABI.cmake:57 (try_compile):
  Executing try_compile (CMAKE_C_ABI_COMPILED) in:

    /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-FdIUbw
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/CMakeTestCCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
  CMakeLists.txt:19 (project)


-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
CMake Debug Log at /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/CMakeDetermineCompilerABI.cmake:57 (try_compile):
  Executing try_compile (CMAKE_CXX_ABI_COMPILED) in:

    /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-yYKKZw
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/CMakeTestCXXCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
  CMakeLists.txt:19 (project)


-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Loading Zephyr default modules (Zephyr workspace).
-- Application: /Users/todi/xxx/zephyr-workspace/firmware
-- CMake version: 3.28.1
-- Found Python3: /opt/homebrew/bin/python3 (found suitable version "3.11.7", minimum required is "3.8") found components: Interpreter 
-- Cache files will be written to: /Users/todi/Library/Caches/zephyr
-- Zephyr version: 3.4.99 (/Users/todi/xxx/zephyr-workspace/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nrf52840dk_nrf52840
-- Found toolchain: gnuarmemb (/usr/local/gcc-arm-none-eabi-8-2019-q3-update)
-- Found Dtc: /opt/homebrew/bin/dtc (found suitable version "1.7.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /Users/todi/xxx/zephyr-workspace/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Generated zephyr.dts: /Users/todi/xxx/zephyr-workspace/lfirmware/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /Users/todi/xxx/zephyr-workspace/firmware/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: /Users/todi/xxx/zephyr-workspace/firmware/build/zephyr/dts.cmake
Parsing /Users/todi/xxx/zephyr-workspace/zephyr/Kconfig
Loaded configuration '/Users/todi/xxx/zephyr-workspace/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
Merged configuration '/Users/todi/xxx/zephyr-workspace/firmware/prj.conf'
Configuration saved to '/Users/todi/xxx/zephyr-workspace/firmware/build/zephyr/.config'
Kconfig header saved to '/Users/todi/xxx/zephyr-workspace/firmware/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: /usr/local/gcc-arm-none-eabi-8-2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.bfd (found version "2.32.0") 
-- The ASM compiler identification is GNU
-- Found assembler: /usr/local/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gcc
-- Performing Test check_C__nostartfiles__nostdlib__isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include___isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include_fixed___Wl___unresolved_symbols_ignore_in_object_files__Wl___entry_0
CMake Debug Log at /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/Internal/CheckSourceCompiles.cmake:101 (try_compile):
  Executing try_compile
  (check_C__nostartfiles__nostdlib__isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include___isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include_fixed___Wl___unresolved_symbols_ignore_in_object_files__Wl___entry_0)
  in:

    /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/Internal/CheckCompilerFlag.cmake:18 (cmake_check_source_compiles)
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/CheckCCompilerFlag.cmake:51 (cmake_check_compiler_flag)
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/extensions.cmake:2003 (check_c_compiler_flag)
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/extensions.cmake:1095 (check_compiler_flag)
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/kernel.cmake:144 (zephyr_check_compiler_flag)
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/zephyr_default.cmake:138 (include)
  /Users/todi/xxx/zephyr-workspace/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
  /Users/todi/xxx/zephyr-workspace/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:148 (include_boilerplate)
  CMakeLists.txt:27 (find_package)


-- Performing Test check_C__nostartfiles__nostdlib__isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include___isystem___usr_local_gcc_arm_none_eabi_8_2019_q3_update_bin____lib_gcc_arm_none_eabi_8_3_1_include_fixed___Wl___unresolved_symbols_ignore_in_object_files__Wl___entry_0 - Failed
CMake Error at /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/extensions.cmake:2252 (message):
  Assertion failed: The toolchain is unable to build a dummy C file.  See
  CMakeError.log.
Call Stack (most recent call first):
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/kernel.cmake:145 (assert)
  /Users/todi/xxx/zephyr-workspace/zephyr/cmake/modules/zephyr_default.cmake:138 (include)
  /Users/todi/xxx/zephyr-workspace/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
  /Users/todi/xxx/zephyr-workspace/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:148 (include_boilerplate)
  CMakeLists.txt:27 (find_package)


-- Configuring incomplete, errors occurred!

According to modules/kernel.cmake:145, this seems to be the very first test, just invoking the C compiler without any additional flags. The actual test that is running, is within the temporary make file (at the end of the error message .../CMakeFiles/CMakeScratch/TryCompile-5jAHCd). If I execute that make file, to find out what is actually executed, then this yield:

cd /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd && /opt/homebrew/Cellar/cmake/3.28.1/bin/cmake -E cmake_depends "Unix Makefiles" /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd /Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd/CMakeFiles/cmTC_61e5d.dir/DependInfo.cmake
Dependencies file "CMakeFiles/cmTC_61e5d.dir/src.c.o.d" is newer than depends file "/Users/todi/xxx/zephyr-workspace/firmware/build/CMakeFiles/CMakeScratch/TryCompile-5jAHCd/CMakeFiles/cmTC_61e5d.dir/compiler_depend.internal".
Consolidate compiler generated dependencies of target cmTC_61e5d
/Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_61e5d.dir/build.make CMakeFiles/cmTC_61e5d.dir/build
[ 50%] Linking C executable cmTC_61e5d
/opt/homebrew/Cellar/cmake/3.28.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_61e5d.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/cc  -nostartfiles -nostdlib -isystem "/usr/local/gcc-arm-none-eabi-8-2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/include" -isystem "/usr/local/gcc-arm-none-eabi-8-2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/include-fixed" -Wl,--unresolved-symbols=ignore-in-object-files -Wl,--entry=0 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk -mmacosx-version-min=13.6 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_61e5d.dir/src.c.o -o cmTC_61e5d 
ld: unknown options: --unresolved-symbols=ignore-in-object-files --entry=0 
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [cmTC_61e5d] Error 1
make[1]: *** [CMakeFiles/cmTC_61e5d.dir/all] Error 2
make: *** [all] Error 2

Then, it looks like the Zephyr build system somehow, recognized the required toolset, by setting some include paths specific to the configuration I gave as input, but: The test is running the OSs default compiler! (/Library/Developer/CommandLineTools/usr/bin/cc). And that one, does not understand the switch that should suppress undefined symbols (--unresolved-symbols=ignore-in-object-files) that is meant for a gcc, while the OSs compiler is actual a clang.

How is this event supposed to work? My understanding of the CMake try_compiler feature is, that one would have to pass a CMAKE_TOOLCHAIN_FILE variable to cmake to change the compiler.

What am I'm doing wrong here? What am I'm missing?

TIA Torsten

Related