Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app size for static libraries vs dynamic frameworks

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

like image 844
corym Avatar asked Jul 25 '18 17:07

corym


Video Answer


1 Answers

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:-

  • The size of the data and code that your executable requires from the library.
  • The capabilities of the compiler and the compilation options. (Clang is compiler.)
  • The capabilities of the linker and the linkage options. (Clang is not a linker.)
  • Possible post-linkage processing of the executable, e.g. stripping.

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.

like image 114
Mike Kinghan Avatar answered Oct 08 '22 07:10

Mike Kinghan