Ubuntu: How to copy libraries a dynamically linked program is built against?


Recently, I've been into compiling software and distributing it. Last time I did it, I did so by building my program and running ldd on it to get all of the libraries it was linked against. I got the path of the library (like say /lib/x86_64-linux-gnu/libc.so.6) and I copied and pasted it from my system. It worked great, but manually copying and pasting each library seemed repetitive. Is there a way that I can just get a list of the paths to the libraries alone (without all of the libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1dc3333000)) so I can copy them and distribute them with my build?


At that point, you are basically building a tarball of an entire Linux distribution. Depending on the libraries you link to, simply including the dynamic library itself may not be enough (some libraries depend on plug-in modules, and other external files, which are not installed in the same locations, as the same versions, across all distributions of Linux).

There are a few options to deal with these differences:

  • Distribute the source code of your program and let the people whom you are distributing to, so that the users my compile it themselves, on their distribution of choice.
  • Re-compile a version of your program for every different version of every different distribution of Linux you wish to support, and distribute your program in packages for those distributions and versions.
  • Compile your application by using static linking, rather than dynamic linking. If you link to libraries that depend on external modules or files though, this can still be problematic.
  • Distribute a VM image of a specific Linux distribution which you wish to support, that is a minimal install, and has your program installed by default, to provide a full environment to run it in.


I have it figured out (mostly).

Let's suppose that the program I built that I plan to distribute is located at /bin/bash. I could create a new directory and run the following command: cp $(ldd /bin/bash) ./

This will give some error messages, but they can be ignored.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »