Why does gcc not support linking dynamic library to static binary

The background is as follows: there is a 3rd party provider that provides us with libveryfancylib.so, in 32b. Softaware, which uses the library, has quite a heavy load on other Linux library dependencies (like QT), but they are open source so there are no problems for static linking. The target platform is 64b and works with Debian 7.

We can ship the program with binaries + dynamic libraries, no problem, but I'd rather see one static binary with no dependencies.

So my question is, why can't I link a dynamic library with a static binary? I mean what piece of information is missing or is it just a feature that is rarely needed -> not implemented.

+3


source to share


3 answers


There are MS Windows programs that can do this, such as DLL for Lib and DLL in Static Lib .



In the open source world, there is little incentive to develop a tool like this that you can always recompile from source (but of course it is possible that someone else did it somewhere).

0


source


We can ship the program with binaries + dynamic libraries, no problem, but I'd rather see one static binary with no dependencies.

What is the problem you are trying to solve?



You can follow the pattern of most commercial applications on Linux: put executables, shared libraries, and other resources in the same directory (possibly with subdirectories). When linking an executable with these shared libraries, pass -Wl,-rpath,'$ORIGIN'

(in use -Wl,-rpath,'$$ORIGIN'

) to the linker so that when the application starts up, the runtime linker looks at the required shared libraries in the same directory as the executable.

Then archive this directory and transfer it to your users.

+1


source


This is because dynamic libraries and static libraries are two different things. A static library is just an archive of object files (like a zip archive). A dynamic library is more like an executable program.

So you cannot link anything in a static library, you can only add additional object files.

0


source







All Articles