Friday, October 7, 2011

What is the difference between static and shared library?

In Unix, Static library has an extension of ".a" which is equivalent to ".lib" in Windows. on the contrary, dynamic or shared library has got ".so" as extension equivqlent to ".dll" in Windows.

Static libraries increase the size of the code in the binary. It is directly linked into the program at compile time. A program using a static library takes copies of the code from the static library and makes it part of the program. They're always loaded with the currently compiled version of the code. As the code is connected at compile time there are not any additional run-time loading costs.

Dynamic libraries are stored and versioned separately. Dynamic libraries aren't necessarily loaded; they are usually loaded when first called and can be shared among components that use the same library (multiple data loads, one code load). It allows you to replace the shared object with one that is functionally equivalent, but may have added performance advantages without needing to recompile the program that makes use of it.Shared libraries will, however have a small additional cost for the execution of the functions as well as a run-time loading cost as all the symbols in the library need to be connected to the things they use. Additionally, shared libraries can be loaded into an application at run-time, which is the general mechanism for implementing binary plug-in systems.

No comments :