Xcode 中的库链接选项是什么?

What are the libraries linking options in Xcode?

从 Xcode 7 开始,在 Xcode

中有一些 library/framework 链接选项

转到项目选项卡中的应用程序 Target

General -> Embedded Binaries
General -> Link Frameworks and Libraries
Build Phases -> Target Dependencies
Build Phases -> Link Binary with Libraries

以下是我找到的几种方法

The Alamofire.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

If you're building for OS X: On your application targets’ “General” settings tab, in the “Embedded Binaries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

If you're building for iOS, tvOS, or watchOS: On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop each framework you want to use from the Carthage/Build folder on disk.

阅读 Linking to a Library or Framework,我们知道这些选项是关于将框架链接到我们的 application/framework。

但是它们之间有什么区别呢? catch all 是否有任何一个选项适用于所有选项?

对于使用 carthage 构建的动态框架,我通常使用以下设置:

  • Link 包含您想在其中使用它的任何目标的库。您需要它才能在您的代码中导入框架。
  • 仅将库嵌入到包含的应用程序目标中。这实际上会将框架复制到您的应用程序包中。如果您不嵌入它,您的应用程序将在启动时崩溃,因为找不到您的框架。

只有应用目标负责嵌入所有框架及其依赖项。这样,如果扩展程序和应用程序都使用一个框架,它只会随应用程序一起分发一次。

对于Xcode接口:

  • 将框架拖入常规 -> 嵌入式二进制文件会将框架添加到 "Link Binary With Libraries" 和 "Embed Frameworks" 构建阶段
  • 将框架拖入常规 -> Linked 框架和库只会将框架添加到 "Link Binary With Libraries" 构建阶段。

常规下的视图似乎是从构建阶段选项卡中填充的,因此您可以使用其中任何一个。

希望这是有道理的。

编辑: 目标依赖项只是在构建当前目标之前需要构建的目标。因此,您的应用目标会在此处列出其扩展,以便在您构建应用时构建扩展。