Link Binary with libraries VS Embed Frameworks
Asked Answered
F

3

86

What's the difference in the build phases between putting a framework in "Link binary with libraries" or in "Embed frameworks"?

Finial answered 19/11, 2014 at 10:59 Comment(1)
I vote to reopen this question, it is not broad, I just found this option myself and was like "What is it? Why do I need it?" It directly compares two options in XCode, and both of them are quite odd. Like saying "Do you want to tie your shoe, or embed the act of tying your shoe? - It is quite confusing.Mccarthy
I
44

Link binary with libraries Link frameworks and libraries with your project’s object files to produce a binary file. You can link a target’s source files against libraries in the target’s active SDK or against external libraries.

Embed Frameworks You can create an embedded framework to share code between your app extension and its containing app.

-

Timeline (Look at this sentence) - "If your containing app target links to an embedded framework, it must include the arm64 architecture or it will be rejected by the App Store."

Interrogation answered 19/11, 2014 at 11:13 Comment(1)
If still confused, this answer helped me more: https://mcmap.net/q/16273/-what-is-the-difference-between-embedded-binaries-and-linked-frameworksTerricolous
I
7

iOS Link vs Embed

For an app target

Xcode 11

  • Static Library
  • Static Framework - Do Not Embed
  • Dynamic Framework - Embed

Pre Xcode 11

  • Static Library - Link
  • Static Framework - Link
  • Dynamic Framework - Embed

How it works [Xcode v11] and [pre Xcode v11]

Infamous answered 14/8, 2019 at 19:9 Comment(0)
P
5

I have been looking at some answers here and there and would like to amend this learning if somebody comes across this question again.

In any case, if we want to use any of a frameworks resources (i.e. the API), we need to link to it. In that case we need to add it in the "Linked Frameworks and Libraries" section in the bottom of the General Target Settings.

If we embed a library we are shipping the library – as it is – with our app bundle. This could be handy e.g. on machines running macOS who certainly do not have a specific 3rd party library.

So, what about iOS? There is no possibility to install 3rd party libraries on an iOS device per se – plus Apple is very strict regarding fat frameworks (libraries built for multiple platforms). So there has to be a way for the libraries to be delivered anyway? Since just linking them is not enough for the user of our application what other possibilities do we have?

That's where a peculiar build phase comes into play. In the project settings under Build Phases there's the link binary with libraries section. This steps strips the unnecessary parts from the fat frameworks and leaves the necessary parts with the bundle so that it is able to run on a device that is agnostic about the app's dependencies.

Perse answered 26/10, 2018 at 12:52 Comment(1)
However, if you just import AVFoundation in an app it is magically linked, as seen in Apple's own AVCam sampleVesperal

© 2022 - 2024 — McMap. All rights reserved.