PDA

View Full Version : Dependency Walker for Mac libraries


kate
2006.08.23, 04:26 AM
Hi,
Is there any free utility that scans dynamic libraries (dylib) and builds a hierarchical tree diagram of all dependent modules.
In Windows there is a utility called Dependency walker http://www.dependencywalker.com/
I want similar utility on Mac.
Thank you.

OneSadCookie
2006.08.23, 05:21 AM
#!/usr/bin/env ruby

paths = [ARGV[0]]
libs = { ARGV[0] => 1 }

while paths.size > 0 do
path = paths.pop
lines = `otool -L '#{path}'`.split("\n")[2..-1]
new_libs = lines.collect do |line|
line =~ /\s+(.*)\s+\(.*\)\s*/
$1
end
new_libs.each do |lib|
if libs[lib] then
libs[lib] += 1
else
libs[lib] = 1
paths << lib
end
end
end

puts libs.keys.sort.join("\n")

kate
2006.08.23, 05:46 AM
Sorry I didnt understand, What should I do with the Code?

OneSadCookie
2006.08.23, 06:57 AM
Put it in a file called libdepend.rb, or something, make it executable with chmod +x, and run it from the terminal something like:

./libdepend.rb /usr/lib/libxslt.dylib

kate
2006.08.24, 12:05 AM
Its working. Thank you.:)