Is there a way to determine what packages or libraries should be loaded to support an executable?
Solution 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.
Solution 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.
Solution 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.
Related videos on Youtube
vfclists
Updated on September 18, 2022Comments
-
vfclists over 1 year
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 itlibpango-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.
-
Admin over 10 yearsWhat OS? The packages and their names as well as the package manager change between distributions (and this is assuming you are running some kind of Linux).
-
Admin over 10 yearsIt is Debian and Ubuntu in this case
-
Admin over 10 yearsIn that case, my answer should work for you.
-
Admin over 10 yearsIn fact I am just about to test it, belatedly. I plain forgot about it and just asked a similar question which caused this one to show as the top related question, LOL
-
-
Alen Milakovic over 10 years
apt-file search
on the actual file on the right side of the arrow might be more effective. -
terdon over 10 years@FaheemMitha very good point, thanks. Answer edited.
-
vfclists over 10 yearsHow can the command be adjusted to test for the existence of the library on the system in order to find those which need to be downloaded? I think the question I asked recently is more along that line. I am asking for it to be reopened.
-
terdon over 10 years@vfclists not worth it really, just
apt-get install
all of them and any that are already installed will be ignored. -
vfclists over 10 yearsThe reason is to create a VM with no superfluous libraries for quick downloads. Package installs contain a lot of unnecessary items and I only need the library files and their dependencies that are required by the executables.It also gives me a chance to hone my bash and Linux skills. No python.
-
terdon over 10 yearsIf you don't want to use packages, you'll have to compile from source and not even use the installation scripts but copy the binaries to the right positions. That's not reinventing the wheel, it's shooting yourself in the leg. Just install the packages. Any that are already installed will be skipped.
-
jcoffland over 8 years
dpkg-query -S <path>
is the way to go. -
Andrew Marshall almost 3 yearsThe problem with
dpkg-query
is that it only searches installed packages whereasapt-file
will search all packages.