Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between static and dynamic library in Xcode for iPhone

What is the difference between a static and dynamic library in XCode? And why doesn't Apple allow us to use dynamic libraries in our iOS applications?

like image 587
prajakta Avatar asked Sep 16 '10 05:09

prajakta


People also ask

What is the difference between static and dynamic library iOS?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.

What is dynamic library in iOS?

Dynamic libraries are usually shared between applications, therefore the system needs to store only one copy of the library and let different processes access it. As a result, invoking code and data from dynamic libraries happens slower than from the static ones. All iOS and macOS system libraries are dynamic.

Should I use static or dynamic library?

The answer depends on the downsides your application can afford. If you have a lot of files, multiple copies of a static library means an increase in the executable file's size. If, however, the benefits of execution time outweigh the need to save space, the static library is the way to go.

What is static library in Xcode?

Static library - .a (aka static archive library, static linked shared library[doc]) - When you add it into your application the static linker during compilation time will merge the object files from the library and package them along with the application object files into one single executable file.


1 Answers

While you can build dynamic libraries for Mac OS X, you cannot use them for iPhone development.

A static library is merely an archive of object files that gets pulled into a program linking against it. The linker will unarchive all the archive files, and pull them in during linking along with the rest of your object files.

A dynamic library however, creates a shared object file, akin to a program but without an entry point, which programs can link against and call out of themselves into these shared libraries for their symbols, without pulling them into itself.

like image 95
jer Avatar answered Sep 20 '22 20:09

jer