5

I have read many articles about static/dynamic library/framework. So my understanding is (let me know if it's inaccurate):

Framework = Library + Bundle
Static = Linking at build time
Dynamic = Linking at run time

In Xcode, we have "Static Library" and "Framework". Which raises a few confusing points:

  • Why there's no "Dynamic Library" option?
  • Given that we can already link framework statically, why do we still need a "Static Library"? (isn't StaticFramework = StaticLibrary + Bundle? )
  • There is not *static framework* - framework is *always* dynamic – Asperi Oct 29 '21 at 09:36
  • @Asperi in cocoapods, there's a static linkage setting for frameworks: `use_frameworks! :linkage => :static` –  Oct 30 '21 at 00:47

2 Answers2

3

Why there's no "Dynamic Library" option?

Because Dynamic Library is not permitted for iOS apps at beginning.

Given that we can already link framework statically, why do we still need a "Static Library"? (isn't StaticFramework = StaticLibrary + Bundle? )

Because old Xcode only support Static Library.

Static Framework was added later, and they keep the Static Library.

JIE WANG
  • 1,875
  • 1
  • 17
  • 27
2

There are many concepts that must be clear

Libraries have two categories based on how they are linked to the executable file

  1. Static library .a, .so. link at compile time. wiki
  2. Dynamic libraries .dylib .dll etc. link at runtime. only apple can use it for iOS for some safe reason, we cannot build this.

ps, a special kind in apple platform

Text Based .dylib stubs — .tbd

Framework

Framework is a package that can contain resources such as dynamic libraries, strings, headers, images, storyboards etc. vs Libraries, Framework has more features

Framework also has static and dynamic

iOS 8 later, we can use a dynamic framework, why Apple releases this. maybe Extension and App share code this Dynamic Framework for iOS is named embedded frameworks, because when we build the app copy the framework in app bundle. so the embedded framework is different from system dynamic Frameworks like UIKit.Framework

Why there's no "Dynamic Library" option?

the embedded library is allowed with the Framework option, but dynamic framework shared in muti app is also not allowed

Given that we can already link framework statically, why do we still need a "Static Library"? (isn't StaticFramework = StaticLibrary + Bundle? )

well, Xcode not only support Objective-c and Swift, but also support C, C++ which may use the static library

king wang
  • 510
  • 2
  • 11