linux/gcc:来自 C/C++ 程序内部的 ldd 功能 [英] linux/gcc: ldd functionality from inside a C/C++ program

查看:15
本文介绍了linux/gcc:来自 C/C++ 程序内部的 ldd 功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单有效的方法来知道给定的动态链接 ELF 缺少运行所需的 .so,所有这些都来自 C 的 内部/C++ 程序?

Is there a simple and efficient way to know that a given dynamically linked ELF is missing a required .so for it to run, all from the inside of a C/C++ program?

我需要一个功能与 ldd 有点相似的程序,而不是尝试执行 ELF 来找出系统中的(满足/未满足)依赖关系.也许通过某个库询问 ld-linux.so 实用程序?(我是linux这部分的新手=)

I need a program with somewhat similar functionality as ldd, without trying to execute the ELF to find out the (met/unmet) dependencies in the system. Perhaps asking the ld-linux.so utility via some library? (I'm a newbie in this part of linux =)

注意:阅读 ldd 的源代码对我的意图不是很有帮助:似乎 ldd 实际上是在分叉另一个进程并执行程序.

NOTE: reading the source code of ldd was not very helpful for my intentions: it seems that ldd is in fact forking another process and executing the program.

如果不执行程序就无法知道程序具有未满足的依赖项,是否有某种方法可以至少从我的程序中快速列出该 ELF 所需的 .so 文件?

If it's not possible to know that a program has unmet dependencies without executing it, is there some way to, at least, quickly list the .so's required for that ELF all from within my program?

提前致谢 =)

推荐答案

根据 ld.so(8),将环境变量 LD_TRACE_LOADED_OBJECTS 设置为非空字符串将给出类似 ldd 的结果(而不是正常执行二进制文件或库).

As per ld.so(8), setting the environment variable LD_TRACE_LOADED_OBJECTS to a non-empty string will give ldd-like results (instead of executing the binary or library normally).

setenv("LD_TRACE_LOADED_OBJECTS", "1", 1);
FILE *ldd = popen("/lib/libz.so");

这篇关于linux/gcc:来自 C/C++ 程序内部的 ldd 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆