Dynamically calling shared objects from statically build executable allowed

Ernesto Castellotti erny.castell at gmail.com
Mon Feb 10 19:39:04 UTC 2020


On Monday, 10 February 2020 at 19:00:36 UTC, Andre Pany wrote:
> On Monday, 10 February 2020 at 13:14:50 UTC, Ernesto 
> Castellotti wrote:
>> On Monday, 10 February 2020 at 04:41:31 UTC, Andre Pany wrote:
>>> Is this a bug with LDC and DMD, or is it not allowed
>>> to dynamically call a SO from a statically build executable 
>>> on linux
>>
>> On Unix systems it is not possible to dynamically load a 
>> library shared by a static executable, I don't know if it 
>> works differently for Windows.
>>
>> This is because it is absolutely necessary to link libdl 
>> dynamically, you cannot link static.
>>
>> For GNU/Linux systems there is this alternative to 
>> dlopen/dlsym that does not require dynamic link: 
>> https://www.gnu.org/software/libtool/manual/html_node/Dlpreopening.html
>
> This is a topic I almost have no knowledge, therefore a 
> question.
>
> If I understand this StackOverflow question correctly, it is 
> possible to call dynamically a shared object from a static 
> library (with dlopen):
>
> https://stackoverflow.com/questions/17862272/dlopen-a-dynamic-library-from-a-static-library-linux-c
>
> But I understand from you it is not possible dynamically call a 
> shared object from a static executable.
>
> Therefore it works for static libraries but not for statically 
> executables?
>
> Kind regards
> Andre

Static libraries are simple collections of object files, there is 
no difference between linking a static library or several object 
files

If you notice when going to compile the executable linka libdl 
and the static library, then the executable will be linked to 
dynamic library and will not be a static executable.



More information about the Digitalmars-d-learn mailing list