技术知识库
生成 ARM64 配置时提示 flex not found
生成 ARM64 配置时提示 flex not found
摘要
执行 debian_defconfig 时没有生成 .config,是因为主机缺少 Kconfig 构建依赖 flex。构建在生成 scripts/kconfig/zconf.lex.c 时已经中止,尚未进入写出配置文件的阶段。仓库说明同时要求安装 bison 和 flex,而当前系统二者都未找到。
目标
为 Linux 5.0 ARM64 构建目录生成配置:
make ARCH=arm64 \
CROSS_COMPILE=aarch64-linux-gnu- \
O=build/arm64 \
debian_defconfig
实际结果与证据
LEX scripts/kconfig/zconf.lex.c
/bin/sh: 1: flex: not found
make[2]: *** [scripts/Makefile.lib:193: scripts/kconfig/zconf.lex.c] Error 127
arch/arm64/configs/debian_defconfig 确实存在,所以目标名称有效。仓库 README.md 第 67 行把 bison flex 列为构建依赖。
原因
Kconfig 的配置语言解析器需要词法分析工具 flex 和语法分析工具 bison。make 已经成功编译若干主机工具,但调用 flex 时 shell 找不到可执行文件,因此退出码为 127,顶层目标随之失败。
修复
安装缺失的主机构建依赖:
sudo apt update
sudo apt install flex bison
然后在源码根目录重新执行原命令。因为指定了 O=build/arm64,成功生成的文件位于:
build/arm64/.config
而不是源码根目录的 .config。
验证
test -f build/arm64/.config && echo "config generated"
grep '^CONFIG_ARM64=' build/arm64/.config
后续可能的依赖
继续编译完整内核时,还需要确认 aarch64-linux-gnu-gcc、bc、OpenSSL 开发包等仓库 README 所列依赖已经安装。若下一次出现新的首个错误,应从第一条明确的 not found 或 error 开始处理。