Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 867
Kumar Utsav Avatar asked Nov 28 '16 10:11

Kumar Utsav


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 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 here Dynamic Library(.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

like image 159
saroj raut Avatar answered Oct 14 '22 17:10

saroj raut


.a stands for Static library

.dylib stands for dynamic library

A Static library (.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.

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 .dylib is a dynamic library: it's a library that's loaded at runtime instead of at compile time. If you're familiar with DLLs from Windows or DSOs, it's more or less the same type of thing with a few twists.

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

like image 21
Wolverine Avatar answered Oct 14 '22 17:10

Wolverine