嵌入式二进制文件和链接框架之间的区别是什么

在使用外部框架时,Xcode 现在有一个 嵌入式二进制文件和一个 连结架构节。

enter image description here

当你下载一个外部框架并且 Finder-> 将其拖放到 Xcode 时,它会将框架放到 链接框架和库部分。

当你用迦太基建立一个库的时候,它建议你拖拽到 嵌入式二进制文件部分。

两者似乎都是在链接方面起作用的,因为 API 以任何一种方式变得可用,当向 嵌入式二进制文件部分添加一个框架时,更进一步的是,它也自动被添加到 链接框架和库部分。

那么,谁是对的?迦太基还是其他网站?为什么在 Xcode 项目中包含外部资源有两种选择?

25182 次浏览

If you embed the binary it will be included into your product. If you only link a library or framework without embedding it, it will not be part of your product.

However, in iOS8 all 3rd party frameworks need to be "embedded". Even a framework that is shared between various programs needs to be "embedded" into every single one of those programs. In the case where it was installed on the device in a shared location, any other installation process using the same "embedded" code from the shared location can re-use that existing installation. This is specific to iOS8, it has not been possible before iOS8 and outside the iOS world this answer would not be accurate.

  1. Linking- We must link a framework if we use any API defined in it.

  2. Embedding - This process will ensure the added framework will be embedded within the App bundle, and potentially will help sharing code between the app, and any extension bundles. We embed only third party frameworks and not the ones provided by iOS as they are readily available in the device. If we are embedding, that means that, we will need to link to them too so that Xcode can compile and create the build. When the app runs in the device, then the embedded framework will be loaded into memory when needed.

To my understand, the embedded binary only includes dynamic framework that is available on iOS 8 and above, otherwise you can only link the framework that is static.

Linking more about Linker that works at compile time or load/run time. Linker copy a Library into a target binary. Since Framework is autonomous, the Linker, in this case, is responsible for find and link the Dynamic Framework inside the system loader path or to find and link inside a bundle.

Embedding is a process of copying the binary into the target binary. As a result it will be located inside.

Read more here

Linking- We must link a framework if we use any API defined in it.

Embedding - This process will ensure the added framework will be embedded within the App bundle, and potentially will help sharing code between the app, and any extension bundles. We embed only third party frameworks and not the ones provided by iOS as they are readily available in the device. If we are embedding, that means that, we will need to link to them too so that Xcode can compile and create the build. When the app runs in the device, then the embedded framework will be loaded into memory when needed

.