Search code examples
c++mergeshared-librarieslinux-distro

problem with different linux distribution with c++ executable


I have a c++ code that runs perfect on my linux machine (Ubuntu Karmic). When I try to run it on another version, I have all sort of shared libraries missing.

Is there any way to merge all shared libraries into single executable?

Edit: I think I've asked the wrong question. I should have ask for a way to static-link my executable when it is already built. I found the answer in ermine & statifier


Solution

  • There are 3 possible reasons you have shared libraries missing:

    • you are using shared libraries which do not exist by default on the other distribution, or you have installed them on your host, but not the other one, e.g. libDBI.so
    • you have over-specified the version at link time, e.g. libz.so.1.2.3 and the other machine has an API compatible (major version 1) but different minor version 2.3, which would probably work with your program if only it would link
    • the major version of the library has changed, which means it is incompatible libc.so.2 vs libc.so.1.

    The fixes are:

    • don't link libraries which you don't need that may not be on different distros, OR, install the additional libraries on the other machines, either manually or make them dependencies of your installer package (e.g. use RPM)
    • don't specify the versions so tightly on the command line - link libz.so.1 instead of libz.so.1.2.3.
    • compile multiple versions against different libc versions.