macos Mac OS X 中的框架到底是什么?( *.framework 文件夹)

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

What exactly is a Framework in Mac OS X? ( *.framework folders )

macosframeworks

提问by Petruza

Ok, I know basically what a framework is in real life. I've seen some frameworks that hold some header files and a binary. Is that it? Does an OS X framework have special features other than just being a folder with headers and libraries you link to your application?

好的,我基本上知道现实生活中的框架是什么。我见过一些包含一些头文件和二进制文件的框架。是这样吗?OS X 框架是否有其他特殊功能,而不仅仅是包含链接到应用程序的头文件和库的文件夹?

回答by Matthew Rankin

Framework Information

框架信息

From the Apple Developer Connection: Framework Definition:

来自Apple Developer Connection:框架定义

A framework is a bundle (a structured directory) that contains a dynamic shared library along with associated resources, such as nib files, image files, and header files. When you develop an application, your project links to one or more frameworks. For example, iPhone application projects link by default to the Foundation, UIKit, and Core Graphics frameworks. Your code accesses the capabilities of a framework through the application programming interface (API), which is published by the framework through its header files. Because the library is dynamically shared, multiple applications can access the framework code and resources simultaneously. The system loads the code and resources of a framework into memory, as needed, and shares the one copy of a resource among all applications.

alt text

框架是一个包(结构化目录),其中包含动态共享库以及相关资源,例如 nib 文件、图像文件和头文件。当您开发应用程序时,您的项目会链接到一个或多个框架。例如,iPhone 应用程序项目默认链接到 Foundation、UIKit 和 Core Graphics 框架。您的代码通过应用程序编程接口 (API) 访问框架的功能,该接口由框架通过其头文件发布。由于库是动态共享的,因此多个应用程序可以同时访问框架代码和资源。系统根据需要将框架的代码和资源加载到内存中,并在所有应用程序之间共享资源的一个副本。

替代文字

From the Framework Programming Guide: What are Frameworks?:

来自框架编程指南:什么是框架?

Frameworks offer the following advantages over static-linked libraries and other types of dynamic shared libraries:

  • Frameworks group related, but separate, resources together. This grouping makes it easier to install, uninstall, and locate those resources.
  • Frameworks can include a wider variety of resource types than libraries. For example, a framework can include any relevant header files and documentation. Multiple versions of a framework can be included in the same bundle. This makes it possible to be backward compatible with older programs.
  • Only one copy of a framework's read-only resources reside physically in-memory at any given time, regardless of how many processes are using those resources. This sharing of resources reduces the memory footprint of the system and helps improve performance.

与静态链接库和其他类型的动态共享库相比,框架具有以下优势:

  • 框架将相关但独立的资源组合在一起。这种分组使安装、卸载和定位这些资源变得更加容易。
  • 框架可以包含比库更广泛的资源类型。例如,一个框架可以包含任何相关的头文件和文档。一个框架的多个版本可以包含在同一个包中。这使得向后兼容旧程序成为可能。
  • 无论有多少进程正在使用这些资源,在任何给定时间,只有一个框架的只读资源的副本物理驻留在内存中。这种资源共享减少了系统的内存占用并有助于提高性能。

Related SO Question

相关问题

You might want to look at SO question 1444543: Differences between Framework and non-Framework builds of Python on Mac OS X.

您可能想查看SO question 1444543: Differences between Framework and non-Framework build of Python on Mac OS X

回答by Petruza

On Mac OS X, a framework is a versioned, bundled library. As you've noticed, some frameworks are quite simple and contain only header files and the library itself for a single version. Other frameworks can have multiple versions, multiple library files, subframeworks (in this case the parent framework is also called an umbrella framework), and resource files such as images or localised strings.

在 Mac OS X 上,框架是一个版本化的捆绑库。正如您所注意到的,一些框架非常简单,只包含单个版本的头文件和库本身。其他框架可以有多个版本、多个库文件、子框架(在这种情况下,父框架也称为伞状框架)和资源文件,例如图像或本地化字符串。

More information available in the Framework Programming Guide.

框架编程指南中提供了更多信息。

回答by double-m

It is, quoting "Mac OS X Technology Overview":

它是,引用“Mac OS X 技术概述”:

framework A type of bundle that packages a dynamic shared library with the resources that the library requires, including header files and reference documentation.

框架 一种捆绑包,将动态共享库与库所需的资源(包括头文件和参考文档)打包在一起。

So a ".framework" is basically the equivalent of a ".app", only for a dynamic shared library instead of an executable.

所以“.framework”基本上相当于“.app”,仅用于动态共享库而不是可执行文件。