分类: Python/Ruby
2013-02-20 10:54:39
#ldd.py import subprocess import sys import os def ldd(filename): global libs libs = [] for x in filename: p = subprocess.Popen(["ldd", x], stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = p.stdout.readlines() for x in result: s = x.split() if "=>" in x: if len(s) == 3: # virtual library pass else: libs.append(s[2]) else: if len(s) == 2: libs.append(s[0]) return libs if __name__ == "__main__": if len(sys.argv) <= 1: print("usage: %s filename1 filename2 ..."%(sys.argv[0])) else: print("\n".join(ldd(sys.argv[1:])))
可以使用一下的命令将文件依赖的动态链接库复制到指定的文件夹中:
./ldd.py file | xargs -i cp {} ./libs
复制file所依赖的动态链接库到libs目录中