Static vs. Dynamic Linking in Operating System (OS)
Static vs Dynamic Linking in OSOn this page will discuss aboutStatic vs Dynamic Linking .A computer program that accepts one or multiple object files generated by a compiler and integrate them into a single executable program is known as a Linker. Object files are the executable files and used as an output for the loader.
Static Linking vs Dynamic Linking in Operating System
- The process of linking can take place at both compile time and load time. During compilation source code is translated into machine code, and during loading the program gets loaded into the memory.
- The process involves copying the library modules required by the program into a final executable image. The following section discusses the difference between static and dynamic linking process.
Static LinkingStatic Linking is the process of copying all library modules used in the program into the final executable code.
Dynamic LinkingDynamic Linking is the process of using only the name of the shared library module in the program.
Head-to-head Comparison between the Static and Dynamic Linking in Operating System
|Static Linking||Dynamic Linking|
|Files that are statically linked are larger in size as they contain external programs with their details.||Dynamically linked files are smaller.|
|The process is conducted by programs known as linkers. It is the last step in the compilation of a program.||Dynamic linking is performed at run time by the operating system.|
|If any external program changes, then it require recompilation, and relinking, else the changes will not be reflected in the existing executable files.||Individual shared modules can be updated and recompiled. The programs can be changed as many times as needed.|
|Programs under static linking take constant load time each time they are loaded into the memory for execution.||The load time must be minimized if the shared library code is already present in the memory.|
|Programs that use this method are comparatively faster as they contain all the data and information necessary for processing.||These programs are usually slower than those using the static linking library.|
|All the code, in this case, is contained in a single executable file, and thus these programs never face compatibility issues.||A compatible library is necessary in this case. In the case of a changed library, the applications need a rework to make them more compatible with the new library. Also, if a library is removed from the system, programs that use this library will not work.|
The difference can be seen in the diagram below which describes the association of library codes in the case of static as well as dynamic linking.
Once the linking is done, the combined program is moved into memory. In this method, the data packets and instructions must have addresses assigned to them as they are needed for the execution process.
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others