In: Computer Science
Why would you choose to use dynamic (shared) library linkage compared to static? Identify at least two advantages of dynamic over static. Describe at least one case where static is preferable. If it “feels” like all the advantages of each have already been listed by your classmates, comment on other students’ postings indicating why you support their perspective.
To understand the various differences between static & dynamic library linkage and to elaborate their specific advantages & disadvantages, we could conclude the below points herewith :-
1) Static linking is the process of copying all library modules used in the program into the final executable image. This is performed by the linker and it is done as the last step of the compilation process. The linker combines library routines with the program code in order to resolve external references, and to generate an executable image suitable for loading into memory. When the program is loaded, the operating system places into memory a single file that contains the executable code and data. This statically linked file includes both the calling program and the called program.
While on the other hand, In dynamic linking the names of the external libraries (shared libraries) are placed in the final executable file while the actual linking takes place at run time when both executable file and libraries are placed in the memory. Dynamic linking lets several programs use a single copy of an executable module.
2) Static linking is performed by programs called linkers as the last step in compiling a program. Linkers are also called link editors.
While on the other hand, Dynamic linking is performed at run time by the operating system.
3) Statically linked files are significantly larger in size because external programs are built into the executable files.
While on the other hand, In dynamic linking only one copy of shared library is kept in memory. This significantly reduces the size of executable programs, thereby saving memory and disk space.
4) In static linking if any of the external programs has changed then they have to be recompiled and re-linked again else the changes won't reflect in existing executable file.
While on the other hand, In dynamic linking this is not the case and individual shared modules can be updated and recompiled. This is one of the greatest advantages dynamic linking offers.
5) Statically linked program takes constant load time every time it is loaded into the memory for execution.
While on the other hand, In dynamic linking load time might be reduced if the shared library code is already present in memory.
6) Programs that use statically-linked libraries are usually faster than those that use shared libraries.
While on the other hand, Programs that use shared libraries are usually slower than those that use statically-linked libraries.
7) In statically-linked programs, all code is contained in a single executable module. Therefore, they never run into compatibility issues.
While on the other hand, Dynamically linked programs are dependent on having a compatible library. If a library is changed (for example, a new compiler release may change a library), applications might have to be reworked to be made compatible with the new version of the library. If a library is removed from the system, programs using that library will no longer work.
A major disadvantage of Dynamic Library is that they take more time to load and get the program running because the linking occurs at run-time instead of during compilation. Since there will be no dynamic querying of symbols in static libraries, many software/application still use Static Library for better speed.