xcode ios中.dylib和.a lib有什么区别?

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

What is the difference between .dylib and .a lib in ios?

iosxcodeframeworksstatic-libraries

提问by Kumar Utsav

I know what is compile and runtime in Objective c, (method swizzling is a runtime) but I want to know what draws the line between these two library? one .a and .dylib ? What purpose do they serve, other than stating one is static and the other is dynamic? When would we need one over the other?

我知道什么是 Objective c 中的编译和运行时(方法 swizzling 是一个运行时),但我想知道这两个库之间的界限是什么?一个 .a 和 .dylib ?除了声明一个是静态的,另一个是动态的之外,它们的目的是什么?我们什么时候需要一个?

回答by saroj raut

Static Library(.a)

静态库(.a)

Static libraries allow an application to load code into its address space at compile time.This results in a larger size on disk and slower launch times. Because the library's code is added directly to the linked target's binary, it means that to update any code in the library, the linked target would also have to be rebuilt. enter image description hereDynamic Library(.dylib)

静态库允许应用程序在编译时将代码加载到其地址空间中。这会导致更大的磁盘空间和更慢的启动时间。因为库的代码直接添加到链接目标的二进制文件中,这意味着要更新库中的任何代码,也必须重新构建链接目标。 动态库(.dylib)在此处输入图片说明

Dynamic libraries allow an application to load code into its address space when it's actually needed at run time. Because the code isn't statically linked into the executable binary, there are some benefits from loading at runtime. Mainly, the libraries can be updated with new features or bug-fixes without having to recompile and relink executable. In addition, being loaded at runtime means that individual code libraries can have their own initializers and clean up after their own tasks before being unloaded from memory

动态库允许应用程序在运行时实际需要时将代码加载到其地址空间中。因为代码不是静态链接到可执行二进制文件中的,所以在运行时加载有一些好处。主要是,可以使用新功能或错误修复来更新库,而无需重新编译和重新链接可执行文件。此外,在运行时加载意味着各个代码库可以有自己的初始化程序,并在从内存中卸载之前清理自己的任务

enter image description here

在此处输入图片说明

回答by Wolverine

.a stands for Static library

.dylib stands for dynamic library

.a 代表静态库

.dylib 代表动态库

A Static library (.a)

静态库 (.a)

A Static library (.a) is a pack of compiled classes, functions which can be used together with iOS app development project. It is a compiled binary or fat file and can be shared between projects.

静态库 (.a) 是一组已编译的类、函数,可与 iOS 应用程序开发项目一起使用。它是一个编译后的二进制文件或胖文件,可以在项目之间共享。

You might want to create a static library for different reasons.

您可能出于不同的原因想要创建一个静态库。

For example:

例如:

  • You want to bundle a number of classes that you and/or your colleagues in your team use regularly and share those easily around.

  • You want to be able to keep some common code centralized so you can easily add bugfixes or updates.

  • You'd like to share a library with a number of people, but not allow them to see your code. -

  • 您希望将您和/或您团队中的同事经常使用的许多课程捆绑在一起,并轻松地分享这些课程。

  • 您希望能够集中一些公共代码,以便您可以轻松地添加错误修正或更新。

  • 您想与许多人共享一个库,但不允许他们看到您的代码。——

Dynamic Library

动态库

A file ending in the extension .dylibis a dynamic library: it's a library that's loaded at runtime instead of at compile time. If you're familiar with DLLsfrom Windows or DSOs, it's more or less the same type of thing with a few twists.

以扩展名.dylib结尾的文件是一个动态库:它是一个在运行时而不是在编译时加载的库。如果您熟悉来自 Windows 或 DSO 的DLL,它或多或少是相同类型的东西,但略有不同。

dylibare analogous to a windows *.dll file. They contain generic, unmodifiable code intended to be reused by many applications.

dylib类似于 windows *.dll 文件。它们包含旨在被许多应用程序重用的通用的、不可修改的代码。