flyingbin
flyingbin

Reputation: 1097

Programming way to list shared library dependency on linux

Is there any programming way (system call?) to list shared library dependency on Linux? Instead of using ldd ...

Upvotes: 7

Views: 2988

Answers (4)

dashesy
dashesy

Reputation: 2643

This is the simple bash script I use myself on Fedora, it relies on find-requires of rpm package, you can look inside find-requires to find what tools it internally uses.

#!/bin/bash
#
# Use rpm to recursively list dependencies of all files in a directory
#
# Syntax:
#   lsdep path/to/directory
# Example:
#   lsdep /usr/src/kernels/`uname -r`/

find $1 -type f -exec sh -c 'res=`echo '{}' | /usr/lib/rpm/find-requires`; [ -n "$res" ] && (echo;echo file '{}'; echo $res)' \;

Upvotes: 0

linuxbuild
linuxbuild

Reputation: 16133

readelf -Wa lib.so|grep NEEDED

Upvotes: 4

ks1322
ks1322

Reputation: 35708

Set LD_TRACE_LOADED_OBJECTS environment variable to non-empty string and run your binary. Look at this man page.

LD_TRACE_LOADED_OBJECTS
    (ELF only) If set to non-empty string, causes the program to list its dynamic library dependencies, as if run by ldd(1), instead of running normally. 

Upvotes: 0

Related Questions