什么时候必须将框架和库链接到 XCode 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33728359/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:12:33  来源:igfitidea点击:

When do you have to link Frameworks and Libraries to an XCode project?

iosxcodeswiftcore-dataframeworks

提问by Yonny

Background: I started a test Swiftproject to understand and expand my knowledge on how to implement CoreDatainto my projects. And of course whenever I'm just testing and playing around with code, I always get sidetracked and seem to get stuck on some tangential topic. This one now being when is it necessary that you directly link a Framework or Library to an XCode project.

背景:我开始了一个测试Swift项目,以了解和扩展我对如何在CoreData我的项目中实施的知识。当然,每当我只是测试和玩弄代码时,我总是会跑偏,似乎卡在一些切题上。现在是什么时候需要将框架或库直接链接到 XCode 项目。

So how this came up... I'm creating subclasses of NSManagedObjectfor which I have to (write) import CoreDatain my Swiftfile. And everything seems to be working perfect; no errors, warnings, etc. However when I check which frameworks and libraries are linked to my project in my "project and targets listing" none are listed. I then realize same goes for when you have to import UIKit. Obviously there's the option to directly link these frameworks but it doesn't seem it is necessary to do so.

那么这是如何出现的......我正在创建NSManagedObject我必须import CoreData在我的Swift文件中(写入)的子类。一切似乎都很完美;没有错误、警告等。但是,当我在“项目和目标列表”中检查哪些框架和库链接到我的项目时,没有列出。然后我意识到当你不得不这样做时也是如此import UIKit。显然,可以选择直接链接这些框架,但似乎没有必要这样做。

So as for my question, are there default frameworks that don't have to be explicitly linked to XCode projects, or will I have to eventually link these frameworks when I package up my project for deployment? And if this is not the case, from a broader standpoint, when is it necessary to explicitly link Frameworks and Libraries to an XCode project?

所以至于我的问题,是否有默认框架不必显式链接到 XCode 项目,或者我在打包项目以进行部署时最终必须链接这些框架?如果不是这种情况,从更广泛的角度来看,什么时候需要将框架和库明确链接到 XCode 项目?

Edit***

编辑***

If all Apple frameworks are already automatically linked.... Then what is the point of having them available to add to your project. (Mind you, CoreData.frameworkwasn't originally linked explicitly like it is in the picture.)

如果所有 Apple 框架都已自动链接......那么将它们添加到您的项目中有什么意义。(请注意,CoreData.framework最初并没有像图片中那样明确链接。)

Project Settings

项目设置

回答by boraseoksoon

There is no magic happening.

This is because of module and auto-linking introduced by Xcode(LLVM).
(related keywords : @import rather than #importand build-setting options like Enable Modules, Link frameworks automatically, by default, set to YES both). enter image description here

没有魔法发生。

这是因为 Xcode(LLVM) 引入了模块和自动链接。
(相关关键字:@import 而不是 #import和构建设置选项,如启用模块、自动链接框架,默认情况下,都设置为 YES)。 在此处输入图片说明

Automatically, these two keyword(module, auto-linking flag options) combinations try to find and add any related all frameworks that support modules.

As introduced from Xcode 5(actually, LLVM and clang compiler front-end), Internally, the LLVM with above default projects setting has been to use the module system to automatically link any frameworks in code through @import/#import statements.

Once the frameworks are automatically linked with that, developers don't need to put them in Linked Frameworks & Libraries anymore.

自动地,这两个关键字(模块,自动链接标志选项)组合尝试查找并添加任何相关的所有支持模块的框架。

正如从Xcode 5(实际上是LLVM和clang编译器前端)引入的,在内部,具有上述默认项目设置的LLVM已经使用模块系统通过@import/#import语句自动链接代码中的任何框架。

一旦框架自动与之链接,开发人员就不再需要将它们放在链接的框架和库中。

So, That's why Apple system frameworks(default frameworks) do not have to be explicitly linked to Xcode projects.

所以,这就是为什么 Apple 系统框架(默认框架)不必显式链接到 Xcode 项目的原因。

Since the module was available in Xcode, there is no need to continue to import all system frameworks list in .pch file(precompiled prefix header.) So, that's why also pch setup is set to NO and no needed by default behind the scene.

由于该模块在 Xcode 中可用,因此无需继续导入 .pch 文件中的所有系统框架列表(预编译的前缀头)。因此,这就是为什么 pch setup 也设置为 NO 并且在幕后默认不需要的原因。

The limitation, as far as I know so far, is these are only available for Apple system frameworks until now, meaning it cannot be applied to user frameworks and other C/C++ libraries.

到目前为止,据我所知,这些限制仅适用于 Apple 系统框架,这意味着它不能应用于用户框架和其他 C/C++ 库。

Hope it helps.

希望能帮助到你。