OSX dynamic linked library dependency tracker and plotter

OSX dependency tracker

Introduction

This page provides and describes a .dylib dependency tracker tool for OSX. Complex dependencies can exist between dynamic linked libraries (.dylib files). If one of them is missing, an application may fail to load. Therefore an application may work fine on one machine, and fail on another one, even with the same OS version and architecture. The tool below enables you to figure out all dependencies and even make a nice plot of them.

Download the tool

zip file (40kb). The zip file contains 5 bash script files. You will need to change the script permissions to executable, using a shell command chmod u+x *.sh
This cell contains some technical details for someone wanting to know more about this tool.The core of this tool is a very simple bash script:
occurences=`grep -cw $2 /tmp/dylibs`
echo $1 " needs " $2 >> /tmp/dylibs
if [ $occurences -eq 0 ] ; then
   otool -l $2 | awk '/ name/ { print $2 }' | xargs -n 1 dylibdeps1.sh $2
fi

Using the dependency tracker

The command dylibdeps.sh <.dylib file> traces all dependencies and prints them to stdout as a list of pairs the form XXX needs YYY, where XXX and YYY are dynamic linked libraries.

For example, the command dylibdeps.sh /usr/lib/libdl.dylib gives:

root needs /usr/lib/libdl.dylib
/usr/lib/libdl.dylib needs /usr/lib/libSystem.B.dylib
/usr/lib/libSystem.B.dylib needs /usr/lib/libSystem.B.dylib
/usr/lib/libSystem.B.dylib needs /usr/lib/system/libmathCommon.A.dylib
/usr/lib/system/libmathCommon.A.dylib needs /usr/lib/system/libmathCommon.A.dylib
/usr/lib/libdl.dylib needs /usr/lib/system/libmathCommon.A.dylib

Using the dependency plotter

You can also make a graphical presentation of the dependencies, using the needs2gml.sh <.needs file>. The needs2gml file takes the output as listed by the dylibdeps.sh command, but it only works from file so you have to save the needs2gml output first. Needs2gml outputs a gml formatted file to the stdout, but to open it you need to put it to a .gml file. So you need 3 steps:

(1) save the dependency tracker output to a .needs file
(2) run the .needs file through the needs2gml.sh converter and save to a .gml file
(3) open the resulting .gml file in yEd or another graph editor capable of layouting gml files

Example.
(1) dylibdeps.sh /usr/lib/libdl.dylib > /tmp/tmp.needs
(2) needs2gml.sh /tmp/tmp.needs > /tmp/tmp.gml
(3) open yEd and select the /tmp/tmp.gml file. All labels are on top of another now
(4) select in yEd the menu Layout/Hierarchical/Interactive and press OK
Now you should have a vector-format figure like below:




© W.Pasman, 29/5/08