编译U-Boot时<built-in>:1错误含义及compiler.h包含路径解析
<built-in>:1含义与头文件包含路径梳理 一、“In file included from :1:”的具体含义
<built-in>是Clang编译器用来指代内部隐式生成的编译上下文的标识,:1表示该上下文的第一行。
本次编译命令中带有-include ./include/compiler.h参数——这个参数会让编译器在处理目标源文件tools/envcrc.c之前,自动将指定头文件作为第一个包含项插入,相当于在envcrc.c的最开头手动添加#include "./include/compiler.h"。由于这个包含操作是编译器幕后强制完成的,不属于源文件本身的代码,因此编译器将其归类到<built-in>上下文,报错时就会显示从<built-in>:1开始引入compiler.h。
二、tools/envcrc.c到compiler.h的完整包含路径
tools/envcrc.c并未通过代码中的#include语句直接引入compiler.h,而是通过编译命令行的强制参数实现的,完整路径链为:
<built-in>(编译器隐式强制包含步骤) →./include/compiler.h
错误日志中的嵌套包含链补充
从错误信息可以看到,compiler.h又进一步包含了其他头文件,引发后续CONFIG_IS_ENABLED未定义错误,典型嵌套链示例:
<built-in>:1→./include/compiler.h:23→include/errno.h:28<built-in>:1→./include/compiler.h:24→include/stdlib.h:9→include/malloc.h:369→include/linux/string.h:21→./arch/arm/include/asm/string.h:4→include/config.h:4→include/configs/qemu-arm.h:33
附:相关编译命令与错误日志
$ gcc -v -Wp,-MD,tools/.envcrc.o.d -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11 -DCONFIG_FIT_SIGNATURE -DCONFIG_FIT_SIGNATURE_MAX_SIZE=0xffffffff -DCONFIG_FIT_CIPHER -include ./include/compiler.h -idirafterinclude -idirafter./arch/arm/include -I./scripts/dtc/libfdt -I./tools -DUSE_HOSTCC -D__KERNEL_STRICT_NAMES -D_GNU_SOURCE -c -o tools/envcrc.o tools/envcrc.c clang version 11.1.0 Target: aarch64-apple-darwin Thread model: posix InstalledDir: "/nix/store/vj903fik1afanjnrmkxxlf56lxharyrn-clang-11.1.0/bin" (in-process) "/nix/store/vj903fik1afanjnrmkxxlf56lxharyrn-clang-11.1.0/bin/clang-11" -cc1 -triple arm64-apple-macosx11.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name envcrc.c -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu apple-a13 -target-feature +v8.3a -target-feature +crypto -target-feature +crc -target-feature +fullfp16 -target-feature +lse -target-feature +neon -target-feature +ras -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 530 -v -nostdsysteminc -resource-dir "/nix/store/b9bh3z78rqff14bf0fd78xb07b5cnwdw-clang-wrapper-11.1.0/resource-root" -dependency-file tools/.envcrc.o.d -MT tools/envcrc.o -sys-header-deps -include ./include/compiler.h -idirafter include -idirafter ./arch/arm/include -idirafter "/nix/store/amkqyy3v347mkdd9x1116nawinnc1r3j-libSystem-11.0.0/include" -isystem "/nix/store/zfya80qwrpl6lf06k8r9dmjvgi9rzdam-libcxx-11.1.0-dev/include" -isystem "/nix/store/m0jxx2yxfw0pma1l9ajnhlsmdqdl6mn2-libcxxabi-11.1.0-dev/include" -isystem "/nix/store/yrig22cjci7sdr8csgr8l0bhkjprxfd8-dtc-1.6.1/include" -isystem "/nix/store/xdrpnixj0wijcb2gqkah3gz4cx3b89iz-flex-2.6.4/include" -isystem "/nix/store/a3kk9mqy6axn7k0zg46r6jg03gs4vgv2-openssl-1.1.1q-dev/include" -isystem "/nix/store/9lmynkzmnzdhnq6j0ckwqs2fvv7lxr0n-python3-3.10.6-env/include" -D CONFIG_FIT_SIGNATURE -D CONFIG_FIT_SIGNATURE_MAX_SIZE=0xffffffff -D CONFIG_FIT_CIPHER -I ./scripts/dtc/libfdt -I ./tools -D USE_HOSTCC -D __KERNEL_STRICT_NAMES -D _GNU_SOURCE -internal-isystem "/nix/store/b9bh3z78rqff14bf0fd78xb07b5cnwdw-clang-wrapper-11.1.0/resource-root/include" -O2 -Wall -Wstrict-prototypes -std=gnu11 -fdebug-compilation-dir "/Users/zaripov-kamil/Documents/code/nixpkgs/u-boot-2022.07" -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -vectorize-loops -vectorize-slp -o tools/envcrc.o -x c tools/envcrc.c clang -cc1 version 11.1.0 based upon LLVM 11.1.0 default target aarch64-apple-darwin21.2.0 #include "..." search starts here: #include <...> search starts here: ./scripts/dtc/libfdt ./tools "/nix/store/zfya80qwrpl6lf06k8r9dmjvgi9rzdam-libcxx-11.1.0-dev/include" "/nix/store/m0jxx2yxfw0pma1l9ajnhlsmdqdl6mn2-libcxxabi-11.1.0-dev/include" "/nix/store/yrig22cjci7sdr8csgr8l0bhkjprxfd8-dtc-1.6.1/include" "/nix/store/xdrpnixj0wijcb2gqkah3gz4cx3b89iz-flex-2.6.4/include" "/nix/store/a3kk9mqy6axn7k0zg46r6jg03gs4vgv2-openssl-1.1.1q-dev/include" "/nix/store/9lmynkzmnzdhnq6j0ckwqs2fvv7lxr0n-python3-3.10.6-env/include" "/nix/store/b9bh3z78rqff14bf0fd78xb07b5cnwdw-clang-wrapper-11.1.0/resource-root/include" include ./arch/arm/include "/nix/store/amkqyy3v347mkdd9x1116nawinnc1r3j-libSystem-11.0.0/include" End of search list. In file included from <built-in>:1: In file included from ././include/compiler.h:23: include/errno.h:28:5: error: function-like macro 'CONFIG_IS_ENABLED' is not defined #if CONFIG_IS_ENABLED(ERRNO_STR) ^ In file included from <built-in>:1: In file included from ././include/compiler.h:24: In file included from include/stdlib.h:9: In file included from include/malloc.h:369: In file included from include/linux/string.h:21: In file included from ./arch/arm/include/asm/string.h:4: In file included from include/config.h:4: include/configs/qemu-arm.h:33:5: error: function-like macro 'CONFIG_IS_ENABLED' is not defined #if CONFIG_IS_ENABLED(CMD_USB) ^ include/configs/qemu-arm.h:39:5: error: function-like macro 'CONFIG_IS_ENABLED' is not defined ... fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
内容的提问来源于stack exchange,提问作者Kamil Zaripov

