gpt4 book ai didi

gcc - 为什么 ld 的 KEEP() 不保留我的符号?

转载 作者:行者123 更新时间:2023-12-04 16:50:07 25 4
gpt4 key购买 nike

通常,通过使用 KEEP(),ld 会保留节中的符号,即使未引用符号也是如此。然而,这不是我的经验。如果未引用符号,我无法创建保留符号的 ld 链接描述文件。

这个工作是否有一些先决条件?

最佳答案

KEEP 确实保留了我的符号,但是所提供的文件被预先删除了所有被认为不需要的目标文件。为防止出现这种情况,必须在链接命令中使用选项 --whole-archive

来自 ld 的手册页:

   --whole-archive
For each archive mentioned on the command line after the
--whole-archive option, include every object file in the archive in
the link, rather than searching the archive for the required object
files. This is normally used to turn an archive file into a shared
library, forcing every object to be included in the resulting
shared library. This option may be used more than once.

Two notes when using this option from gcc: First, gcc doesn't know
about this option, so you have to use -Wl,-whole-archive. Second,
don't forget to use -Wl,-no-whole-archive after your list of
archives, because gcc will add its own list of archives to your
link and you may not want this flag to affect those as well.

关于gcc - 为什么 ld 的 KEEP() 不保留我的符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19101088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com