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

There is an executable I want to install on a computer that I can’t recompile that wasn’t built as a package, and I want to download the libraries it requires to run them.

Below is part of the output from running ldd on it

libpango-1.0.so.0 => /usr/lib/i386-linux-gnu/libpango-1.0.so.0 (0xb702f000)
libcairo.so.2 => /usr/lib/i386-linux-gnu/libcairo.so.2 (0xb6f64000)
libatk-1.0.so.0 => /usr/lib/i386-linux-gnu/libatk-1.0.so.0 (0xb6f43000)
libsqlite3.so.0 => /usr/lib/i386-linux-gnu/libsqlite3.so.0 (0xb6e9e000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6cf4000)
/lib/ld-linux.so.2 (0xb786e000)
libxcb.so.1 => /usr/lib/i386-linux-gnu/libxcb.so.1 (0xb6cd3000)
libgio-2.0.so.0 => /usr/lib/i386-linux-gnu/libgio-2.0.so.0 (0xb6b7c000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6b4f000)

Is there a tool that can use this information to select which packages should be downloaded or better yet extract only the libraries listed and their dependencies, in order to minimize the disk usage? The system is running on a headless VM and the program will be displayed via VNC.

Although I suspect that a full blown graphics desktop will supply most of the libraries needed I want to download only the required libraries, their dependencies and just enough of the X Windows package to support it.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

@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.

Method 3

Your best bet is to find a package that actually supports your distribution. But if that is not going to work for you then I know only one other way.

Run ldd as you have, then manually install those dependencies.

For example libpango-1.0.so.0 => /usr/lib/i386-linux-gnu/libpango-1.0.so.0 (0xb702f000)

For me would mean installing apt-get install libpango:i386 and praying that the version in Debian unstable was good enough.

You would need to go through each line of ldd, Google, look in your available repositories, and basically get lucky. Then install them one by one. Till the program actually runs. ldd will only work for “simple” programs though. Programs that call plugins or that run arbitrary code are a different matter all together. For those you will need to run from the console, and fix the crashes/errors as they happen.

That said, a binary only executable is horridly hard to maintain. You may want to consider using something else. If your distro is a little ahead, or a little behind the system that built that executable, you may never get it to work.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x