4

我知道ldd只能将二进制文件作为其参数,我在这里要问的是如何使用二进制文件运行ldd,例如,mybin带有二进制文件的参数。例如,mybin --myparam ./configfile.conf.

如果我为我的二进制文件添加 conf 文件,链接器会有所不同,因为它会在运行时使用插件的共享对象文件加载一些插件,plugin1.so就像这样。我有一些未定义的参考问题,但我仍然不知道.so我丢失了哪个文件。

如果我运行ldd ./mybin,所有内容都已链接并且运行普通二进制文件就可以了。一旦我为我的二进制文件添加了 conf 文件,让它加载一些插件共享库,那么我的二进制文件将在加载这些库时报告错误(编码异常抛出,带有一些undefined reference错误消息)。

因此,如果有办法运行这样lddmybin --myparam ./a.file东西会很有帮助。

4

1 回答 1

3

为此使用LD_DEBUG环境变量。要查看相关选项,请运行任何带有LD_DEBUG=help. 例如,LD_DEBUG=help ls在我的机器上运行会给出以下输出:

LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  scopes      display scope information
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

调试您dlopen的 s 或您正在使用的任何后期加载机制的一种方法是使用相关 args 运行您的可执行文件LD_DEBUG=all。这将为您提供冗长的输出,详细说明符号查找和搜索路径。此输出还会告诉您解析失败。

于 2015-07-13T16:35:55.657 回答