Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why gcc does not support linking dynamical library into static binary

The background is following: there is 3'rd party provider that provides us with a libveryfancylib.so, in 32b. Softaware that uses the library has quite a load of other linux library dependencies (like QT) also, but they are open source, so no problem for statical linking. The target platform is 64b and running Debian 7.

We can ship the program with binary + dynamical libraries, no problem, but i would rather see single static binary with no dependencies.

So my question is: why i cannot link the dynamical library into static binary? I mean what bit of information is there missing, or is it just feature that is rarely needed -> not implemented.

like image 357
susundberg Avatar asked Apr 29 '26 20:04

susundberg


1 Answers

We can ship the program with binary + dynamical libraries, no problem, but i would rather see single static binary with no dependencies.

What is the problem you are trying to solve?

You can follow the model most commercial applications on Linux do: put your executable, shared libraries and other resources in one directory (possibly with subdirectories). When linking your executable against those shared libraries pass -Wl,-rpath,'$ORIGIN' (in make use -Wl,-rpath,'$$ORIGIN') to the linker, so that when starting your application the runtime linker looks for required shared libraries in the same directory where executable is.

Then archive that directory and give it to your users.

like image 198
Maxim Egorushkin Avatar answered May 01 '26 10:05

Maxim Egorushkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!