断言失败:工具链无法构建虚拟 C 文件

Posted

技术标签:

【中文标题】断言失败:工具链无法构建虚拟 C 文件【英文标题】:Assertion Failed: The toolchain is unable to build a dummy C file 【发布时间】:2021-03-07 04:30:01 【问题描述】:

一些学生和我自己一直在尝试在 Windows 10 下建立 Zephyr RTOS 构建环境,以构建针对各种 ARM Cortex M 板的应用程序。我们每个人都遵循了 Zephyr“入门指南”并遇到了同样的问题。当为许多不同的板子编译时(这里我们以 nrf52840dk_nrf52840 为例)我们得到这个错误:

错误信息

C:\Users\John\code\eip-zephyr>west build -p auto -b nrf52840dk_nrf52840 .\zephyr\samples\basic\blinky\
-- west build: generating a build system
Including boilerplate (Zephyr base): C:/Users/John/code/eip-zephyr/zephyr/cmake/app/boilerplate.cmake
-- Application: C:/Users/John/code/eip-zephyr/zephyr/samples/basic/blinky
-- Zephyr version: 2.4.0 (C:/Users/John/code/eip-zephyr/zephyr)
-- Found Python3: C:/Python39/python.exe (found suitable exact version "3.9.0") found components: Interpreter
-- Found west (found suitable version "0.8.0", minimum required is "0.7.1")
-- Board: nrf52840dk_nrf52840
-- Cache files will be written to: C:/Users/John/code/eip-zephyr/zephyr/.cache
-- Found toolchain: gnuarmemb (C:/gnu_arm_embedded)
-- Found BOARD.dts: C:/Users/John/code/eip-zephyr/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
-- Generated zephyr.dts: C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/zephyr/include/generated/devicetree_unfixed.h
Parsing C:/Users/John/code/eip-zephyr/zephyr/Kconfig
Loaded configuration 'C:/Users/John/code/eip-zephyr/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840_defconfig'
Merged configuration 'C:/Users/John/code/eip-zephyr/zephyr/samples/basic/blinky/prj.conf'
Configuration saved to 'C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/zephyr/.config'
Kconfig header saved to 'C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/zephyr/include/generated/autoconf.h'
-- The C compiler identification is GNU 9.3.1
-- The CXX compiler identification is GNU 9.3.1
-- The ASM compiler identification is GNU
-- Found assembler: C:/gnu_arm_embedded/bin/arm-none-eabi-gcc.exe
CMake Error at ../../../cmake/extensions.cmake:1569 (message):
  Assertion failed: The toolchain is unable to build a dummy C file.  See
  CMakeError.log.
Call Stack (most recent call first):
  ../../../CMakeLists.txt:42 (assert)


-- Configuring incomplete, errors occurred!
See also "C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/CMakeFiles/CMakeOutput.log".
See also "C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/CMakeFiles/CMakeError.log".
FATAL ERROR: command exited with status 1: 'C:\Program Files\CMake\bin\cmake.EXE' '-DWEST_PYTHON=c:\python39\python.exe' '-BC:\Users\John\code\eip-zephyr\build\nrf52840dk_nrf52840\blinky' '-SC:\Users\John\code\eip-zephyr\zephyr\samples\basic\blinky' -GNinja -DBOARD=nrf52840dk_nrf52840

此错误将我们指向文件:CMakeError 和 CMakeOutput。以下是它们的内容:

CMakeError

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/gnu_arm_embedded/bin/arm-none-eabi-gcc.exe 
Build flags: 
Id flags:  

The output was:
1
c:/gnu_arm_embedded/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/gnu_arm_embedded/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/gnu_arm_embedded/bin/arm-none-eabi-gcc.exe 
Build flags: 
Id flags:  

The output was:
1
c:/gnu_arm_embedded/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/gnu_arm_embedded/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status

CMakeOutput

The target system is: Generic - 2.4.0 - arm
The host system is: Windows - 10.0.19041 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/gnu_arm_embedded/bin/arm-none-eabi-gcc.exe 
Build flags: 
Id flags: -c 

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.o"

The C compiler identification is GNU, found in "C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/CMakeFiles/3.19.0/CompilerIdC/CMakeCCompilerId.o"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/gnu_arm_embedded/bin/arm-none-eabi-gcc.exe 
Build flags: 
Id flags: -c 

The output was:
0


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.o"

The CXX compiler identification is GNU, found in "C:/Users/John/code/eip-zephyr/build/nrf52840dk_nrf52840/blinky/CMakeFiles/3.19.0/CompilerIdCXX/CMakeCXXCompilerId.o"

Checking whether the ASM compiler is GNU using "--version" matched "(GNU assembler)|(GCC)|(Free Software Foundation)":
arm-none-eabi-gcc.exe (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我的问题:

    这个错误是什么意思? 如何修复它,以便成功构建应用程序。

【问题讨论】:

这能回答你的问题吗?***.com/questions/64834134/… 我不知道如何测试那个。该链接表示与--specs=nosys.specs 标志链接。它实际上并没有解释如何将这些标志放入 Zephyr 构建系统。 【参考方案1】:

在 zephyr-rtos slack 频道中挖掘并获得其他人的帮助后,我发现其他人也遇到了同样的问题,所以我将在这里发布我的修复,希望它也能解决其他人的问题。

修复是双重的:

    您必须从 CMake 3.19 降级。大多数在此工作之前,但推荐使用 3.17.2 版本。如果您使用的是 Windows,则可以使用 Chocolatey 命令:choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System' --version 3.17.2 --allow-downgrade --force。 您必须删除 .cache 文件夹。您之前的构建输出会告诉您它将存储在哪里。该行以如下开头:“-- 缓存文件也将被写入:...”

我仍然不知道为什么会抛出这个错误,或者应该做些什么来永久修复它,但这是目前的修复。

【讨论】:

【参考方案2】:

只是想通知 Zephyr 存储库中目前正在处理一种解决方法。看看这里:https://github.com/zephyrproject-rtos/zephyr/pull/30272

【讨论】:

以上是关于断言失败:工具链无法构建虚拟 C 文件的主要内容,如果未能解决你的问题,请参考以下文章

buildroot 构建交叉编译工具链

如何构建MIPS交叉编译工具链

在使用自定义工具链时包括CLion检查的目录

Flutter - 在 ABI 的 NDK 工具链文件夹中找不到工具链

无法使用 Kivy 工具链为 iOS 编译第三方包

在 CentOS 上构建整个工具链的教程