Xcode 中的库链接选项是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34834717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the libraries linking options in Xcode?
提问by onmyway133
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 Alamofireshows
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 Frameworkshows that adding the
Library.xcodeproj
into workspace, thenBuild Phases -> Link Binary with Libraries
Carthage Tutorial: Getting Startedshows that dragging
Library.framework
intoGeneral -> Link Frameworks and Libraries
. It seemsGeneral -> Link Frameworks and Libraries
andBuild Phases -> Link Binary with Libraries
are the sameCarthageseems to differentiate between iOS and OS X.
创建您的第一个 iOS 框架表明将 加入
Library.xcodeproj
到工作区,然后Build Phases -> Link Binary with Libraries
迦太基教程:入门表明,拖
Library.framework
成General -> Link Frameworks and Libraries
。似乎General -> Link Frameworks and Libraries
和Build Phases -> Link Binary with Libraries
是一样的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.
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.
如果您正在为 OS X 构建:在您的应用程序目标的“常规”设置选项卡上的“嵌入式二进制文件”部分中,从磁盘上的 Carthage/Build 文件夹中拖放您想要使用的每个框架。
如果您正在为 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.
阅读链接到库或框架,我们知道这些选项是关于将框架链接到我们的应用程序/框架。
But what are the differences between them? Is any single option a catch all
for all of them?
但是它们之间有什么区别呢?是否有任何一个选项catch all
适用于所有人?
回答by Kay
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.
只有 app 目标负责嵌入所有框架及其依赖项。这样,如果扩展程序和应用程序都使用框架,它只会与应用程序一起分发一次。
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
- dragging a framework into General -> Linked Frameworks and Libraries will add the framework only to the "Link Binary With Libraries" build phase.
- 将框架拖入 General -> Embedded Binaries 会将框架添加到“Link Binary With Libraries”和“Embed Frameworks”构建阶段
- 将框架拖到 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.
常规下的视图似乎是从构建阶段选项卡中填充的,因此您可以使用其中任何一个。
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.
编辑:目标依赖项只是在构建当前目标之前需要构建的目标。因此,您的应用程序目标将在此处列出其扩展程序,以便在您构建应用程序时构建扩展程序。