Difference between static and dynamic library in Xcode for iPhone
Asked Answered
P

4

19

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?

Ptolemy answered 16/9, 2010 at 5:3 Comment(0)
S
12

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.

Shalna answered 16/9, 2010 at 5:7 Comment(1)
You cannot make use of custom dynamic libraries on iOS devices at present writing, unless they are apple provided. Read: ship with the SDK. I hope this clears it up for you.Shalna
R
4

A dynamic library wouldn't make any sense for an iphone app as there is no way to install the library on the phone. I remember reading some documentation where apple stated they decided not to use dynamic libraries as they didn't want users to have to deal with hassles of finding/updating libraries. Much easier to just install 1 bundle per app.

Radiotherapy answered 16/9, 2010 at 5:55 Comment(0)
E
1

Apple does allow you to make dynamic libraries. On Mac OS X, these end in .bundle or .dylib (not .so or .a like on Linux).

What, specifically are you trying to do? Did you create a target for your dylib?

Edger answered 16/9, 2010 at 5:6 Comment(1)
i am talking about i-phone .a filePtolemy
L
0

iOS static vs dynamic library

  • Static library(.a) - library which copies all it's content into a target at compile time. That is why compile time is slower and result file is bigger, but there is no delay in run time

  • Dynamic library(.dylib) - library which has a single copy in a system where linking happens during run time. That is why compile time is faster, footprint of output file is smaller but there are some delays in runtime. Dynamic library is prerogative of OS(a lot of system libraries are dynamic) and as a developer you are not able to create it. Since such type of library is shared between different applications it should be secure and support IPC

  • Dynamic framework - framework with Dynamic library inside. Apple presented Dynamic framework and App extension[About] from iOS v8. You are able to use it inside single application to share common code and resources inside app sandbox

[Vocabulary]

Louisiana answered 26/9, 2022 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.