linux / gcc:ldd从C / C ++程序中的功能 [英] linux/gcc: ldd functionality from inside a C/C++ program

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

问题描述

有没有一种简单有效的方法来知道给定的动态链接的 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 来查找系统中的(met / unmet)依赖关系。也许通过一些图书馆问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.

如果不可能知道程序没有执行未满足的依赖关系,有没有办法,至少可以快速列出所需的。code> ELF 全部来自我的程序?

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:ldd从C / C ++程序中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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