链接器 --whole-archive 选项

Linker --whole-archive option

我正在使用 C 语言。

我正在将静态库与 --whole-archive 链接起来。链接器是 arm-none-eabi-ld

例如,为链接器提供以下选项:

--whole-archive abc.a def.a

但我仍然遇到链接错误:

(.text.boot+0x94): undefined reference to `xyz'
...

为什么会出现链接错误?

编辑:

带输出的完整命令:

make[1]: Entering directory '/home/Project1/kern'
arm-none-eabi-ld -o /home/Project1/kernel.elf -T memmap.ld  \
     hal/arm/arm_startup.o --whole-archive kunit.a hal.a fs.a --no-whole-archive /home/Project1/lib/lpc.a
hal/arm/arm_startup.o: In function `start':
(.text.boot+0x94): undefined reference to `mmu_init'
hal/arm/arm_startup.o: In function `halt':
(.text.boot+0x98): undefined reference to `exec_array'
hal.a(arm_int_handlers.o): In function `interrupt_svc':
(.text+0x18): undefined reference to `mmu_pagetable'
hal.a(arm_int_handlers.o): In function `interrupt_svc':
(.text+0x5c): undefined reference to `_enter_kernel'
...

输出:

readelf -Ws kunit.a hal.a fs.a | egrep ' (mmu_init|exec_array|mmu_pagetable|_enter_kernel)'

是:

     9: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND mmu_pagetable
    10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND _enter_kernel
    12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND mmu_pagetable

Why is the linking error happening?

因为您缺少的符号:mmu_initmmu_pagetable实际上 未在您期望的库中定义定义于.

这就是 readelf 输出中的 UND 的意思。

现在,为了告诉您为什么这些符号没有定义,我们需要知道您希望它们被定义的库的来源,这些符号是如何定义的图书馆已经建成,可能还有很多其他细节。请单独提问所有你能想到的细节