[英]Is there a C++ API Linux System call that tells you which shared libraries your executable has linked?
我想知道是否有人知道产生类似于 ldd 命令的 output 的 C++ 系统调用。 我正在尝试获取我正在运行的可执行文件已链接的所有共享库的列表(就像 ldd,但 C++ API)。 我的最终目标是获取我的程序链接到的所有共享库的绝对路径。
您可以使用dl_iterate_phdr :
#define _GNU_SOURCE
#include <link.h>
#include <stdlib.h>
#include <stdio.h>
static int callback(struct dl_phdr_info *info, size_t size, void *data) {
printf("name=%s (%d segments)\n", info->dlpi_name, info->dlpi_phnum);
return 0;
}
int main() {
dl_iterate_phdr(callback, NULL);
return 0;
}
该程序将产生以下 output:
name= (9 segments)
name= (4 segments)
name=/lib64/libdl.so.2 (7 segments)
name=/lib64/libc.so.6 (10 segments)
name=/lib64/ld-linux-x86-64.so.2 (7 segments)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.