编译内核 报错 -mlittle-endian

本文介绍了解决交叉编译内核时遇到的“cc1:error: unrecognized command line option -mlittle-endian”错误的方法。通过设置正确的编译参数,如使用ARCH=arm和CROSS_COMPILE=arm-linux-,可以成功规避该问题。
部署运行你感兴趣的模型镜像

交叉编译内核出现

cc1: error: unrecognized command line option "-mlittle-endian"

解决办法:

命令行加入 ARCH=arm CROSS_COMPILE="arm-linux-"或

export CROSS_COMPILE="arm-linux-"

export ARCH=arm

make zImage

您可能感兴趣的与本文相关的镜像

GPT-oss:20b

GPT-oss:20b

图文对话
Gpt-oss

GPT OSS 是OpenAI 推出的重量级开放模型,面向强推理、智能体任务以及多样化开发场景

gcc: error: unrecognized argument in option ‘-mabi=aapcs-linux’ gcc: note: valid arguments to ‘-mabi=’ are: ms sysv gcc: error: unrecognized command line option ‘-mlittle-endian’ gcc: error: unrecognized command line option ‘-mno-thumb-interwork’ gcc: error: unrecognized command line option ‘-mfpu=vfp’ scripts/Makefile.build:258: recipe for target 'scripts/mod/empty.o' failed make[2]: *** [scripts/mod/empty.o] Error 1 scripts/Makefile.build:403: recipe for target 'scripts/mod' failed make[1]: *** [scripts/mod] Error 2 make[1]: *** Waiting for unfinished jobs.... HOSTCC scripts/dtc/checks.o HOSTCC scripts/dtc/util.o Generating include/generated/mach-types.h SHIPPED scripts/dtc/dtc-lexer.lex.c SHIPPED scripts/dtc/dtc-parser.tab.h SHIPPED scripts/dtc/dtc-parser.tab.c HOSTCC scripts/dtc/dtc-lexer.lex.o CC kernel/bounds.s gcc: error: unrecognized argument in option ‘-mabi=aapcs-linux’ gcc: note: valid arguments to ‘-mabi=’ are: ms sysv gcc: error: unrecognized command line option ‘-mlittle-endian’ gcc: error: unrecognized command line option ‘-mno-thumb-interwork’ gcc: error: unrecognized command line option ‘-mfpu=vfp’ Kbuild:43: recipe for target 'kernel/bounds.s' failed make[1]: *** [kernel/bounds.s] Error 1 Makefile:990: recipe for target 'prepare0' failed make: *** [prepare0] Error 2 make: *** Waiting for unfinished jobs.... HOSTCC scripts/dtc/dtc-parser.tab.o HOSTLD scripts/dtc/dtc Makefile:555: recipe for target 'scripts' failed make: *** [scripts] Error 2
04-01
你提供的这一段 Makefile 代码主要用于根据 CPU 的大小端配置(`CONFIG_CPU_BIG_ENDIAN` 或 `CONFIG_CPU_LITTLE_ENDIAN`)来设置 C 编译器和汇编器的编译选项。以下是详细解析: --- ### 📜 代码逐行解析 ```makefile ifndef CONFIG_CC_IS_CLANG cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align endif ``` - **`ifndef CONFIG_CC_IS_CLANG`**:如果 `CONFIG_CC_IS_CLANG` 没有被定义(即不是使用 Clang 编译器),则执行下面的语句。 - **`cflags-$(CONFIG_CPU_LITTLE_ENDIAN)`**:如果 `CONFIG_CPU_LITTLE_ENDIAN` 被定义为 `y`,则 `$(CONFIG_CPU_LITTLE_ENDIAN)` 展开为 `y`,于是 `cflags-y` 会被追加 `-mno-strict-align`。 - **`-mno-strict-align`**:关闭严格的内存对齐检查,适用于某些架构(如 ARM)在小端模式下运行时允许非对齐访问。 --- ```makefile cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian) ``` - 如果 `CONFIG_CPU_BIG_ENDIAN=y`,则向 `cflags-y` 添加 `-mbig-endian`。 - **`$(call cc-option,-mbig-endian)`**:尝试使用 `-mbig-endian` 选项,如果不支持则静默忽略。 --- ```makefile cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian ``` - 如果是小端模式,则添加 `-mlittle-endian` 编译选项。 --- ```makefile aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian) aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian ``` - 同样逻辑,但用于汇编器(`aflags`),即控制汇编代码的大小端设置。 --- ### 🧩 编译器选项说明 | 选项 | 含义 | |------|------| | `-mbig-endian` | 编译为大端模式 | | `-mlittle-endian` | 编译为小端模式 | | `-mno-strict-align` | 允许非对齐内存访问(常用于小端 ARM 架构) | | `$(call cc-option,...)` | 尝试添加编译器选项,不支持则忽略 | --- ### ✅ 总结 | 条件 | 添加的标志 | 用途 | |------|------------|------| | `CONFIG_CPU_BIG_ENDIAN=y` | `-mbig-endian`(C 和汇编) | 设置编译器为大端模式 | | `CONFIG_CPU_LITTLE_ENDIAN=y` 且非 Clang | `-mno-strict-align` | 关闭严格对齐 | | `CONFIG_CPU_LITTLE_ENDIAN=y` | `-mlittle-endian`(C 和汇编) | 设置编译器为小端模式 | --- ### 🛠 示例:如何查看这些标志是否生效? 你可以在 Makefile 中加入: ```makefile $(info cflags-y = $(cflags-y)) $(info aflags-y = $(aflags-y)) ``` 或者在编译时通过: ```bash make V=1 ``` 查看完整的编译命令行,确认是否包含上述选项。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值