You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Clang构建Cortex-M0固件时LLD链接报错:KEEP(*.init_array)语法错误修复咨询

Fixing LLD Linker Error: "( expected, but got )" on KEEP(*.init_array) for Cortex-M0

Let's break down what's happening here and how to resolve this quickly:

The Root Cause

GNU ld (the linker bundled with GCC) allows a convenient shorthand for selecting sections in linker scripts—you can write *.init_array instead of the explicit *(.init_array). However, LLD enforces stricter adherence to the official linker script grammar, which requires that section matching patterns are wrapped in parentheses immediately after the wildcard *.

Your error line KEEP(*.init_array) uses the GNU ld shorthand that LLD doesn't recognize. It expects the fully compliant KEEP(*(.init_array)) syntax instead.

The Fix

Update the problematic line (and any other matching instances in your script) to include the required parentheses:

KEEP(*(.init_array))  // Replaces the original KEEP(*.init_array)

While you're editing, scan the rest of your linker script for other shorthand section references. For example, if you see KEEP(*.fini_array) later in the script, adjust that to KEEP(*(.fini_array)) as well to avoid similar errors.

Why This Works for GCC but Not Clang/LLD

GNU ld has supported these shorthand notations as a legacy convenience, but LLD was built to follow the linker script specification more strictly. This strictness eliminates ambiguity and ensures better consistency with standard script syntax across different toolchains.

Verify the Fix

After making the syntax adjustments, re-run your Clang build command. The linker error should disappear, and your firmware should complete linking successfully just like it does with GCC.

内容的提问来源于stack exchange,提问作者filo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 03:09:10