gpt4 book ai didi

c++ - 为带有参数的二进制文件运行 ldd

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:01:29 39 4
gpt4 key购买 nike

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

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

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

所以如果有办法用 mybin --myparam ./a.file 运行 ldd 像这样的东西会有很大帮助。

最佳答案

为此使用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 或您正在使用的任何延迟加载机制的一种方法是使用相关参数和 LD_DEBUG=all 运行您的可执行文件。这会给你一个冗长的输出,详细说明符号查找和搜索路径。此输出还会告诉您有关解析失败的信息。

关于c++ - 为带有参数的二进制文件运行 ldd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388248/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com