通常,通过使用 KEEP(),ld 将符号保留在节中,即使未引用符号也是如此。然而,这不是我的经验。如果未引用符号,我无法创建保留符号的 ld 链接描述文件。
是否有一些先决条件才能起作用?
通常,通过使用 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.