【问题标题】:Run ldd for a binary with parameter对带有参数的二进制文件运行 ldd
【发布时间】:2015-07-13 16:07:05
【问题描述】:

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

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

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

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

【问题讨论】:

  • 尝试跟踪找到有问题的库,然后在该库上运行ldd
  • @KerrekSB 哦,是的,您的评论也很有用,因为我实际上有可以运行 ldd 的共享库路径。

标签: c++ parameters shared-libraries ldd


【解决方案1】:

为此使用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.

调试dlopens 或您使用的任何延迟加载机制的一种方法是使用LD_DEBUG=all 运行带有相关参数的可执行文件。这将为您提供冗长的输出,详细说明符号查找和搜索路径。此输出还会告诉您解决失败的情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多