Shared, Static , Dynamic?

if I could compile the same source file as shared/static/dynamic what are the advantages/ disadv of each.

PS:by dynamic i am asking about usage of "dlopen". How is it particularly diff from shared libs

static means it has all of the external libraries "internal" - so it never has to worry about library versions being correct. These image files are huge and use a lot of memory. Image activation takes longer and uses more resources than shared, especially in the event that the file is called inside a shell script loop, for example. Deployment of these is usually a slam-dunk

shared means it has all of the external libraries "external" - so it always has to worry about library versions being correct and opening them. These image files are small and use relatively smaller memory allocations. They load faster. Deployment can be iffy, so installation requires a full check of the versions of externale libraries.

There is advantage to dynamic, in that it allows you to specify exactly which versions of libraries to open, if you chose to do that. This also allows you to override LD_LIBRARY_PATH settings.

1 Like

Another means you can load libraries you didn't necessarily know about when the program was compiled. Someone could build an external plugin for your program and tell it about its existence in a commandline parameter for example.