【问题标题】:Linker --whole-archive option链接器 --whole-archive 选项
【发布时间】:2020-06-09 03:30:36
【问题描述】:

我正在使用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

【问题讨论】:

  • 您提供的信息有限,几乎不可能说出问题所在。至少给出导致链接错误的完整构建命令。您用来得出结论的任何输出也会有所帮助。
  • exact 错误信息是什么?你确定是xyz 而不是xyz() 吗?
  • @EmployedRussian Post 已更新。我相信xyzxyz()
  • @kaylum 更新后
  • 你能添加来自readelf -Ws kunit.a hal.a fs.a | egrep ' (mmu_init|exec_array|mmu_pagetable|_enter_kernel)'的输出吗(都在单行上)。

标签: c linux linker arm embedded-linux


【解决方案1】:

为什么会出现链接错误?

因为您缺少的符号:mmu_initmmu_pagetable实际上没有在您希望定义它们的库中定义。

这就是UNDreadelf 输出中的含义。

现在,为了告诉您为什么这些符号没有定义,我们需要知道您希望在其中定义它们的库的来源、这些库是如何构建的,以及可能还有很多其他细节。请用所有你能想到的细节提出一个单独的问题。

【讨论】:

  • UND 反对mmu_pagetable,但没有反对mmu_init。这是否意味着 mmu_pagetablemmu_init 都没有定义?您能否详细解释一下 FULL readelf 命令在做什么以及输出中的不同列。请你把这个放在你的答案中。
  • mmu_init 是从 hal/arm/arm_startup.o 引用的,所以它在那里是未定义的。 Can you please explain in detail Readelf has it's own documentation 在这里复制它是没有意义的。 also the different columns 一些如果它记录在objdump documentation 中。一般研究ELF文件类型。
猜你喜欢
  • 2010-10-22
  • 2015-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-21
相关资源
最近更新 更多