8

我有一些链接问题。

为了调查这个问题,我添加了-t链接器标志 (gcc -Wl,-t) 来打印使用了哪些库以及使用了静态库中的哪些对象。

有一个静态库,在某些配置中使用一组目标文件,而在另一组中使用。

有什么办法(可能是ld标志)来查看为什么特定对象(在对象文件中定义了以前未定义的符号)链接到二进制文件中,而其他来自同一个静态库的不是?

4

2 回答 2

6

我正在寻找的标志是-M,它将链接映射打印到标准输出。

来自 ld(1):

  -M
  --print-map
      Print a link map to the standard output.  A link map provides information about the link, including the following:
           ·   Where object files are mapped into memory.
           ·   How common symbols are allocated.
           ·   All archive members included in the link, with a mention of the symbol which caused the archive member to be brought in.
           ·   The values assigned to symbols.

列表中的第二项是我正在寻找的。

于 2012-10-25T12:20:46.617 回答
1

由于您在上次编辑问题和答案后一个多月添加了赏金,我假设您不喜欢自己的答案。

据我了解,您正试图找出是什么对象(A)导致其他对象(B)被链接。

如果您在没有 B 存在的情况下进行编译/链接(即在命令行上没有),那么您应该会收到错误消息,告诉您为什么需要它,这将引用 A。

如果 B 在库中,您可能需要制作该库的不包含 B 的特殊版本。

于 2012-12-03T02:59:37.140 回答