PDA

View Full Version : Dependency Walker for Mac libraries


kate
2006-08-23, 03:24
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.

kate
2006-08-24, 03:32
I found solution to my question.
CODE:
#!/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")

1. Put it in a file called libdepend.rb
2. Terminal:
Make it executable with chmod +x libdepend.rb, and
Run it:
./libdepend.rb /usr/lib/libxslt.dylib

Thank you.