Is the distributed app size affected by the choice to use static libraries or dynamic frameworks for dependencies? I read an older article that claimed that Clang is smart enough to only link the symbols that are used by an app if you use a static library, but that is not the case for dynamic frameworks. Is this still the case?
EDIT: clarifying that this is about iOS applications distributed on the App Store
If you have a choice between linking a static build of some library, libfoo.a
,
and a dynamic build of the same library, libfoo.{dynlib|so}
, linking the
static library will very probably make your executable larger than linking the
dynamic library.
The extra weight from static linkage will vary depending on:-
But in general:-
Static linkage entails that the definitions of any symbols that your executable references and are provided by the library must be extracted from the library and physically incorporated into the executable. For a data symbol, the definition is some binary data. For a function symbol, the definition is the binary implementation of the function.
Dynamic linkage entails only that the linker will incorporate in the executable some concisely structured information that the OS loader will interpret, at runtime, as instructions to load the dynamic library from disc into the program's address space and then resolve the programs's references to the symbols that are defined in the library.
Typically, the size of the definitions that need not be incorporated in the executable if they are provided at runtime from a dynamic library is much larger than that of the information that instructs the loader to load the dynamic library.
We have dynamic libraries so that diverse programs that have functionality and/or data values in common do not need to physically incorporate copies of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With