chevron-up bell reply instagram twitter2 feed3 finder search-25px-p0

Static Library,Dynamic Library and Framework in iOS

2016-05-07

What you can get from this article:

  • What are Static Library and Dynamic Library not just in iOS
  • How do they work (in general)

Some concepts about library

  • Reduce coupling: if you want to create a copy of "public code", you have to reduce unnecessary coupling of it.
  • Reduce the compile time
  • Reduce the duplicate code

The difference between Static Lib and Dynamic Lib

Library is a compiled library file, usually in binary format. The other users can use it directly with a header file/files. There are two types of libraries:

  • Static library
    • Linked statically. Related code and addresses will be loaded into main program stright away.
    • It will make the program size bigger
  • Dynamic library
    • Linked dynamically. Related code and addresses will be calculated and then loaded into main program. There will be extra time on this calculation.
    • Will not make the program size bigger.

Static Library

Static Library in different format .lib under Window, .a under Linux or Mac. The whole static library will be loaded into target and stay still during the compile phrase. The benefits of Static Library the target program runs without any outside dependences, i.e. you can copy this program to other systems if you like. But the drawback is it will make the program bigger.

So it will be a good start if you want to make the program size smaller.

Dynamic library

On the contrary, Dynamic library (.dll under Windows, .so under Linux and .dylib/.tbd under Mac) will not be loaded into the target program. Instead the target program only load the references during the compile phrase. The Dynamic library will be just loaded while running.

The benefits of Dynamic library:

  • Compared with Static Library, Dynamic library can be used by multiple programs with just one copy.
  • It is quite easy to upgrade the Dynamic library without recompile the whole program

The bad parts of Dynamic library:

  • Extra compile time on Dynamic library/libraries
  • Easy to get the error such as "lib not found" under linux when you are trying to copy the program to other systems but forget the Dynamic library

iOS Framework

In iOS, Apple is using Framework to package the header files, source files, binary files and resources. Similarly, Framework can be divides into Static Framework and Dynamic Framework.

Before iOS 8, Dynamic Framework is not allowed by Apple. Dynamic Framework is introduced might as the reason of Apple starts supporting Extension. With Extension program, it have all the necessary to have to share the same Framework as it used in corresponding app.

arkilis

Comments: