Is there a way to determine what packages or libraries should be loaded to support an executable?

You have not said which OS you are using so I am going to assume Linux and will use Debian as an example. The quick answer to your question is no as far as I know. This might be a useful workaround though:

ldd your_prog | awk '{print $1}' | sed 's/\..*//' | 
  while read n; do echo "----- $n ----"; apt-cache search ^$n; done

This will parse the ldd output and then run apt-cache (replace that with the equivalent for your OS) to search the repositories for packages whose name and description contains the first part of the library name returned by ldd.

This will not find all of them and will give too many results for some (like libc) but it could be helpful.


@FaheemMitha pointed out that apt-file might be a better way. For example:

ldd /bin/bash | awk '/=>/{print $(NF-1)}'  | 
 while read n; do apt-file search $n; done |
  awk '{print $1}' | sed 's/://' | sort | uniq

That will return a list of package names that provide the linked libraries.


@terdon's answer is great but it is even easier to do this using dpkg-query which unlike apt-file is installed by default on Debian systems.

ldd /bin/bash | awk '/=>/{print $(NF-1)}' | while read n; do dpkg-query -S $n; done | sed 's/^\([^:]\+\):.*$/\1/' | uniq

This produces a list of packages.