【发布时间】:2013-10-06 17:19:17
【问题描述】:
通常,通过使用 KEEP(),即使没有引用符号,ld 也会将符号保留在节中。然而,这不是我的经验。如果未引用符号,我无法创建保留符号的 ld 链接描述文件。
这是否有一些先决条件?
【问题讨论】:
标签: gcc ld linker-scripts
通常,通过使用 KEEP(),即使没有引用符号,ld 也会将符号保留在节中。然而,这不是我的经验。如果未引用符号,我无法创建保留符号的 ld 链接描述文件。
这是否有一些先决条件?
【问题讨论】:
标签: gcc ld linker-scripts
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.
【讨论】: