什么时候在iOS中使用动态链接库?在iOS中使用动态库的优势是什么? [英] When to use dynamic linking library in iOS ? And what is advantage of using dynamic library in iOS?

查看:88
本文介绍了什么时候在iOS中使用动态链接库?在iOS中使用动态库的优势是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Window或Linux和iOS中动态链接库的优势之间的区别感到奇怪.

I feel weird about difference between advantage of dynamic linking library in Window or Linux and iOS.

⬇️句子是为了证明我为什么感到怪异.

⬇️ sentences below are to prove why I feel weird.

我了解到,库可以分为静态库动态库

I learned that library can divided into static library and dynamic library

使用动态库的优点是允许其他应用程序使用相同的动态库(在Window中, .dll文件),以便每个可以减少应用程序的内存使用量,并且重新分发动态库而不是重新分发应用程序可能更容易.其实我在使用某些应用程序时可能会遇到"没有XXX.dll文件" 的情况.

Advantage of using dynamic library is allow other application to use same dynamic library ( in Window, .dll file) so that each of application memory usage can be reduce and it can be easiar to redistribute dynamic library rather than to redistribute application. Actually I could have experienced "there is no XXX.dll file" in using some applications

在Xcode中,当创建新项目时,我们可以在 framework&中选择 framework 静态库.库.在创建项目后,我们可以选择如何成为 Mach-O类型,类似于可执行,动态库,静态库".等.

And in Xcode, when to create new project, we can choice framework and static library in framework & library. And after creating project, we can choice how to being what Mach-O Type is like "Executable, Dynamic Library, Static Library" etc..

因此,我认为,如果在动态库中选择 Mach-O类型,该项目将以链接方式使用动态链接库进行编译.

So, I think that if I choice Mach-O type with Dynamic Library, the project will be compiled using dynamic linking library in linking way.

⬇️我真的很奇怪.

  1. 但是像在Window中一样,iOS用户是否可以在iPhone中下载 .so文件,以便正常运行应用程序或更新动态库?
  2. 在iPhone中启动的其他应用程序可以使用相同的动态库吗?
  1. But like in Window, Could iOS user downloads .so file in their iPhone in order to work normally app or update dynamic library?
  2. Could others app launched in iPhone use same dynamic library ?

因为我对此没有经验.

  1. 如果(1,2)不能,为什么要使用动态库,即使我们无法像在Window或Windows中那样获得使用动态库的实际优势,Linux吗?
  1. If it(1,2) can't be, why to use dynamic library even we couldn't get actual advantage of using dynamic library like in Window or Linux ?

推荐答案

您对动态库和静态库的理解是正确的.

Your understanding of dynamic and static libraries is correct.

已编译的源代码(目标代码,.o文件)和已编译的库代码合并为一个可执行文件[1]

The compiled source code (object code, the .o files) and the compiled library code are combined into a single executable [1]

编译后的源代码(目标代码)和库代码未组合在一起.在应用程序启动或运行时在运行时解析对动态链接库的引用(第二部分不适用于iOS应用程序)[1]

The compiled source code (object code) and the library code are not combined together. The references to the dynamically linked library are resolved at runtime while the app launches or while running (the second part is not applicable in the case of iOS Apps) [1]

iOS从MacOS大量借鉴了其应用程序的工作方式.两个操作系统中的可执行文件都是Mach-O文件.现在,在macOS上,动态链接库或dylib旨在并设计为无需更新整个应用程序即可进行更新.通过设计,这在iOS中也是可能的.阻止这种情况的是Apple的准则,该准则限制应用程序从Internet下载可执行代码.任何新更新都必须经过其审核过程.[2]

iOS borrows heavily from MacOS on how its applications work. Executables in both the OSes are Mach-O files. Now, on macOS dynamically linked libraries or dylibs are intended and designed to be updated without having to update the entire app. And by design, this is possible in iOS as well. What prevents this is Apple's guidelines restricting apps from downloading executable code from the internet. Any new update has to go through their review process. [2]

是的,一些动态链接的库在应用程序之间共享.但是,它们是由Apple通过iOS更新创建和更新的.所有的Apple框架(例如UIKit,SceneKit等)就是此类示例.这就是为什么这些框架在Xcode中使用不嵌入"选项进行弱链接的原因

Yes, some dynamically linked libraries are shared across apps. However, they are created and updated by Apple through iOS updates. All Apple frameworks like UIKit, SceneKit, etc are examples of this. This is why these frameworks are weakly linked in Xcode with the option 'Do Not Embed'

使用自己的dylib并非一无是处.如果您在应用程序中附带扩展程序,则dylib是在应用程序和扩展程序之间共享代码而不增加二进制文件大小的绝佳选择.在这种情况下,可执行文件共享相同的库.[3]

Using your own dylibs are not completely pointless. If you ship extensions in your app, then dylibs are an excellent option to share code between the app and extensions without increasing the binary size. In this case, the executables share the same library. [3]

[1] [2] https://developer.apple.com/app-store/review/guidelines/#app-completeness#2.5.2

[3] https://developer.apple.com/forums/thread/73802

这篇关于什么时候在iOS中使用动态链接库?在iOS中使用动态库的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆