我想知道我的系统上的可执行文件使用了哪些库。更具体地说,我想对使用最多的库以及使用它们的二进制文件进行排名。我该怎么做呢?
当前回答
其他答案忽略了一个重要的问题:
共享库既可以直接链接,也可以通过另一个库间接链接。
仅适用于直接链接:
objdump——private-headers "${bin}" | grep 'NEEDED' | cut——delimiter=' ' ' ——字段= 18岁
所有:
LDD "${bin}" | cut——fields=2 | cut——delimiter=' '——fields=1 | rev | cut——delimiter='/'——fields=1 | rev | sort——unique——version-sort
其他回答
在OS X上默认没有ldd, objdump或lsof。作为替代,尝试otool -L:
$ otool -L `which openssl`
/usr/bin/openssl:
/usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
在本例中,使用哪个openssl填充给定可执行文件和当前用户环境的完全限定路径。
在UNIX系统上,假设二进制(可执行)名称为test。然后我们使用下面的命令列出测试中使用的库
ldd test
我发现这篇文章非常有用,因为我需要调查来自第三方提供的库的依赖关系(32位执行路径vs 64位执行路径)。
我在RHEL 6发行版上基于'readelf -d'建议组合了一个Q&D递归bash脚本。
它是非常基本的,每次都会测试每个依赖项,即使之前可能已经测试过了(即非常冗长)。输出也是非常基本的。
#! /bin/bash
recurse ()
# Param 1 is the nuumber of spaces that the output will be prepended with
# Param 2 full path to library
{
#Use 'readelf -d' to find dependencies
dependencies=$(readelf -d ${2} | grep NEEDED | awk '{ print $5 }' | tr -d '[]')
for d in $dependencies; do
echo "${1}${d}"
nm=${d##*/}
#libstdc++ hack for the '+'-s
nm1=${nm//"+"/"\+"}
# /lib /lib64 /usr/lib and /usr/lib are searched
children=$(locate ${d} | grep -E "(^/(lib|lib64|usr/lib|usr/lib64)/${nm1})")
rc=$?
#at least locate... didn't fail
if [ ${rc} == "0" ] ; then
#we have at least one dependency
if [ ${#children[@]} -gt 0 ]; then
#check the dependeny's dependencies
for c in $children; do
recurse " ${1}" ${c}
done
else
echo "${1}no children found"
fi
else
echo "${1}locate failed for ${d}"
fi
done
}
# Q&D -- recurse needs 2 params could/should be supplied from cmdline
recurse "" !!full path to library you want to investigate!!
将输出重定向到一个文件并grep 'found'或'failed'
使用和修改,当然风险由你自己承担,如你所愿。
要了解二进制文件使用的库,请使用LDD
ldd path/to/the/tool
您必须编写一个小shell脚本来处理系统范围的故障。
在ubuntu上 打印与可执行文件相关的包
ldd executable_name|awk '{print $3}'|xargs dpkg -S |awk -F ":" '{print $1}'
推荐文章
- 如何找到Java堆大小和内存使用(Linux)?
- 遍历带空格的文件列表
- Bash:无限睡眠(无限阻塞)
- 如何使Python脚本在Linux中像服务或守护进程一样运行
- 如何使用文件的行作为命令的参数?
- time_t最终的类型定义是什么?
- 如何使用cut为分隔符指定更多的空格?
- 没有找到Gradlew命令?
- 如何在Vim或Linux中将空格转换为制表符?
- 在一台主机上有多个glibc库
- 如何让命令行参数传递给unix/linux系统上正在运行的进程?
- Linux有c++ gdb图形用户界面吗?
- arm64和armhf有什么区别?
- 当存储命令输出到变量时,如何保存换行符?
- 如何创建一个十六进制转储文件只包含十六进制字符没有空格在bash?