简体   繁体   English

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

[英]What are the libraries linking options in Xcode?

As of Xcode 7, there are some library/framework linking options in Xcode从 Xcode 7 开始,Xcode 中有一些库/框架链接选项

Go to application Target in project tab转到项目选项卡中的应用程序Target

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

Here are a few ways I found这是我找到的几种方法

  • Using Alamofire shows Embedded Binaries option使用Alamofire显示Embedded Binaries选项

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. Alamofire.framework 在复制文件构建阶段自动添加为目标依赖项、链接框架和嵌入式框架,这是您在模拟器和设备上构建所需的全部。

  • Creating your first iOS Framework shows that adding the Library.xcodeproj into workspace, then Build Phases -> Link Binary with Libraries 创建您的第一个 iOS 框架显示将Library.xcodeproj添加到工作区,然后Build Phases -> Link Binary with Libraries

  • Carthage Tutorial: Getting Started shows that dragging Library.framework into General -> Link Frameworks and Libraries . Carthage Tutorial: Getting Started显示将Library.framework拖入General -> Link Frameworks and Libraries It seems General -> Link Frameworks and Libraries and Build Phases -> Link Binary with Libraries are the same似乎General -> Link Frameworks and LibrariesBuild Phases -> Link Binary with Libraries是一样的

  • Carthage seems to differentiate between iOS and OS X. Carthage似乎区分了 iOS 和 OS X。

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.如果您正在为 OS X 构建:在您的应用程序目标的“常规”设置选项卡上,在“嵌入式二进制文件”部分中,从磁盘上的 Carthage/Build 文件夹中拖放您要使用的每个框架。

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.如果您正在为 iOS、tvOS 或 watchOS 构建:在您的应用程序目标的“常规”设置选项卡上,在“链接的框架和库”部分中,将您要使用的每个框架从 Carthage/Build 文件夹拖放到磁盘。

Reading Linking to a Library or Framework , we know that these options are about linking a framework into our application/framework.阅读Linking to a Library or Framework ,我们知道这些选项是关于将框架链接到我们的应用程序/框架。

But what are the differences between them?但是它们之间有什么区别呢? Is any single option a catch all for all of them?是否有任何一个选项可以catch all所有这些选项?

For dynamic frameworks built with carthage I usually use this setup:对于使用 carthage 构建的动态框架,我通常使用以下设置:

  • Link the library with any target you want to use it in. You need this to be able to import the framework in your code.将库与您要在其中使用它的任何目标链接。您需要它才能在您的代码中导入框架。
  • Embed the library only in the containing app target.仅将库嵌入到包含的应用程序目标中。 This will actually copy the framework in your app bundle.这实际上会将框架复制到您的应用程序包中。 If you don't embed it your app will crash on startup, because your framework can't be found.如果你不嵌入它,你的应用程序将在启动时崩溃,因为找不到你的框架。

Only the app target is responsible for embedding all the frameworks and their dependencies.只有应用程序目标负责嵌入所有框架及其依赖项。 That way if an extension and the app both use a framework, it will be distributed with the app only once.这样,如果一个扩展和应用程序都使用一个框架,它只会与应用程序一起分发一次。

For the Xcode interface:对于 Xcode 界面:

  • dragging a framework into General -> Embedded Binaries will add the framework to both "Link Binary With Libraries" and "Embed Frameworks" build phases将框架拖入 General -> Embedded Binaries 会将框架添加到“Link Binary With Libraries”和“Embed Frameworks”构建阶段
  • dragging a framework into General -> Linked Frameworks and Libraries will add the framework only to the "Link Binary With Libraries" build phase.将框架拖入 General -> Linked Frameworks and Libraries 只会将框架添加到“Link Binary With Libraries”构建阶段。

The views under General seem to be filled from the build phases tab so you can use either. General 下的视图似乎是从 build phases 选项卡中填充的,因此您可以使用其中任何一个。

Hope that makes sense.希望这是有道理的。

Edit: Target dependencies are just targets that need to be built before the current target can be built.编辑:目标依赖项只是在构建当前目标之前需要构建的目标。 So your app target would list its extension here, so that the extension gets built, whenever you build your app.因此,您的应用目标会在此处列出其扩展,以便在您构建应用时构建扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM