From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,6014cbf1d77efd04 X-Google-Attributes: gidfee84,public From: Jeff Donsbach Subject: Re: Which libraries are linked in? Date: 1998/06/19 Message-ID: <358AAFB2.A5913CA2@nospam.digital.com> X-Deja-AN: 364265259 Content-Transfer-Encoding: 7bit References: <357D167C.4FAC4EE6@citicorp.com> <35811272.0@rainbow.hrz.uni-siegen.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Digital Equipment Corp., Software Partners Engineering Newsgroups: comp.unix.osf.osf1 Here is a shell script that I got from one of my co-workers that does more or less what "ldd" does. It is a multiplatform script and on a Sun, it just passes the input argument to the real "ldd" command. I don't know about the other platforms, but I just ran it on Digital Unix 4.0B and it seems to work just fine. I haven't fully tested it though (like for cases where something was linked with the "-rpath" linker flag). I'm told that a real "ldd" command will be in the next major release of Digital Unix. -Jeff D Here is the script - #!/bin/sh #------------------------------------------------------------------------------- # # Script to produce consistent dynamic dependency information across platforms. # # Syntax: ldd ... # #------------------------------------------------------------------------------- # # To use the general code at the bottom of this script, you must define the # following three functions:- # # need - Returns the dynamic dependencies for the supplied # file, one per line. If the dependency contains a "/" # character then it will not be subject to a path # search. A second word can be added to any line which # supplies a default name to use if the search should # fail. # # conlib - Converts the supplied file name into a loader library # reference (eg /lib/libc.a -> -lc) if it is of the # correct form. Otherwise the original name will be # returned. # # search - Returns a colon separated search path for locating # the dependencies of the supplied file. # #------------------------------------------------------------------------------- # # Switch on machine type # case `uname` in # # Use ldd for SunOS4 # - Loop over args as pipe suppresses output of filename # SunOS) for file do if [ $# -gt 1 ]; then echo "$file:"; fi /bin/ldd "$file" | sed -e 's/^ / /' -e 's/ => / => /' done exit 0;; # # Define functions for HPUX 9 # HP-UX) need() { chatr $1 2>/dev/null | awk ' \ BEGIN { exe = 0; got = 0; } \ $0 ~ /^[ ]*shared executable[ ]*/ { exe = 1; } \ $0 ~ /^[ ]*demand load executable[ ]*/ { exe = 1; } \ /^[ ]*shared library list:[ ]*$/ { \ got = 1; \ next; \ } \ got != 0 { \ if (NF == 2 && ($1 == "static" || $1 == "dynamic")) { \ if (!exe || got != 1) { \ if ($1 == "static") print $2; \ else { \ for (i=length($2)-1;i>0;i--) \ if (substr($2,i,1) == "/") break; \ print substr($2,i+1),$2; \ } \ } \ got++; \ } \ else got = 0; \ }' } conlib() { echo "$1" | sed -e 's/^lib\(.*\)\.sl$/-l\1/' } search() { temp=`chatr $1 2>/dev/null | awk ' \ BEGIN { got = 0; first=0; shlib=""; embed=""; } \ /^[ ]*shared library dynamic path search:[ ]*$/ { \ got = 1; \ next; \ } \ got != 0 { \ if ($1 == "SHLIB_PATH" && $2 == "enabled") { \ shlib = "$SHLIB_PATH"; \ first = ($3 == "first"); \ } \ if ($1 == "embedded" && $2 == "path" && $3 == "enabled" && (NF != 6 || $5 != "Not" || $6 != "Defined")) { \ first = ($4 != "first"); \ embed = $5; \ for (i=6; i<=NF; i++) embed = embed " " $i; \ } \ if (got++ > 2) exit; \ } \ END { \ if (first) print shlib ":" embed; \ else print embed ":" shlib; \ }'` eval echo "$temp" };; # # Define functions for Mips Irix 5 # IRIX) need() { odump -D $1 2>/dev/null | sed -n 's/^[ ]*NEEDED:[ ]*//p' } rpath() { odump -D $1 2>/dev/null | sed -n 's/^[ ]*RPATH:[ ]*//p' } conlib() { echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \ -e 's/^lib\(.*\)\.so$/-l\1/' } search() { echo "`rpath $1`:$LD_LIBRARY_PATH:/lib:/usr/lib:/lib/cmplrs/cc:/usr/lib/cmplrs/cc" };; # # Define functions for Alpha OSF 1 # OSF1) need() { odump -D $1 2>/dev/null | sed -n 's/^[ ]*NEEDED:[ ]*//p' } rpath() { odump -D $1 2>/dev/null | sed -n 's/^[ ]*RPATH:[ ]*//p' } conlib() { echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \ -e 's/^lib\(.*\)\.so$/-l\1/' } search() { echo "`rpath $1`:$LD_LIBRARY_PATH:/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/lo cal/lib" };; # # Define functions for Solaris 2 # sparc_5) need() { dump -Lv $1 2>/dev/null | sed -n 's/^\[[0-9]*\][ ]*NEEDED[ ]*//p' } rpath() { dump -Lv $1 2>/dev/null | sed -n 's/^\[[0-9]*\][ ]*RPATH[ ]*//p' } conlib() { echo "$1" | sed -e 's/^lib\(.*\)\.so\.[0-9]$/-l\1/' \ -e 's/^lib\(.*\)\.so$/-l\1/' } search() { echo "$LD_LIBRARY_PATH:`rpath $1`:/usr/ccs/lib:/usr/lib" };; # # Unknown platforms # *) echo "$0 Not supported on this platform" exit 1;; esac # # Process files in turn # for file do deps="`need $file`" if [ -z "$deps" ]; then if [ ! -f $file ]; then echo "$file: No such file or directory" else echo "$file: Statically linked"; fi continue fi if [ $# -gt 1 ]; then echo "$file:"; fi scan=`search $file` echo "$deps" | while read name def; do case $name in */*) echo " $name";; *) ( IFS=":" soname="" for path in $scan; do if [ -f "$path/$name" ]; then soname="$path/$name" break; fi done if [ -z "$soname" -a -f "$def" ]; then soname=$def; fi echo " `conlib $name` => ${soname:-(not found)}" );; esac done done -- ========================= Jeff Donsbach Compaq Computer Corporation, Software Partners Engineering 200 Forest St., MRO1-3/F26, Marlborough, MA 01752-3011 Email: Jeff.Donsbach@nospam.digital.com "10 bucks is 10 bucks" - Geddy Lee remove "nospam" to reply