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

I know what compilation and runtime is in Objective-c (the swizzling method is the runtime), but I want to know what draws a line between these two libraries? one .a and .dylib? What purpose do they serve, apart from indicating one, is static and the other dynamic? When will we need one above the other?

+5
source share
2 answers

Static Library (.a)

Static libraries allow an application to load code into its address space at compile time. This results in a larger disk size and slower startup time. Since library code is added directly to the linked target binary, this means that the linked target must also be rebuilt to update any code in the library. enter image description here Dynamic Library (.dylib)

Dynamic libraries allow an application to load code into its address space when it is really needed at runtime. Since the code is not statically linked to executable binary code, there are some advantages of loading at runtime. Basically, libraries can be updated with new features or bug fixes without having to recompile and reuse the executable. In addition, loading at run time means that individual code libraries can have their own initializers and clear them after completing their tasks before unloading them from memory.

enter image description here

+8
source

.a stands for static library

.dylib stands for dynamic library

Static Library (.a)

A static library (.a) is a package of compiled classes that can be used with an iOS application development project. This is a compiled binary or thick file and can be shared between projects.

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

For instance:

  • You want to link several classes that you and / or your colleagues in your team regularly use, and it's easy to share.

  • You want to be able to centrally centralize common code so you can easily add corrections or updates.

  • You like to share the library with several people, but not let them see your code. -

Dynamic library

A file ending in the .dylib extension is a dynamic library: it is a library loaded at runtime, not at compile time. If you are familiar with DLLs from Windows or DSOs, this is more or less the same type of thing with a few twists.

dylib are similar to the windows * .dll file. They contain common non-modifiable code intended for reuse by many applications.

+4
source

Source: https://habr.com/ru/post/1260444/


All Articles