Home > Operation and Maintenance > Linux Operation and Maintenance > What is the difference between dynamic linking and static linking in linux

What is the difference between dynamic linking and static linking in linux

青灯夜游
Release: 2022-02-25 16:02:40
Original
3681 people have browsed it

Difference: 1. Static linking is performed before the executable program is formed, while dynamic linking is performed when the program is executed; 2. The code loading speed of the static link library is faster, and the execution speed is slightly faster than that of the dynamic link library. The link library is fast; 3. Compared with dynamic linking, the executable file generated by static linking is larger.

What is the difference between dynamic linking and static linking in linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

Dynamic linking and static linking in Linux

The process of compilation and linking

Compilation is divided into Step 3: First, preprocess the source file. This process mainly processes some commands or statements defined by # (such as macros, #include, precompilation instructions #ifdef, etc.) to generate *.i files; then compile, this The process is mainly to perform lexical analysis, syntax analysis and semantic analysis to generate *.s assembly files; finally, assembly is performed. This process is relatively simple, which is to translate the corresponding assembly instructions into machine instructions and generate a relocatable binary target file. .

Two ways of linking

  • Static link

  • Dynamic link

The biggest difference between static linking and dynamic linking is that the timing of linking is different. Static linking is performed before the executable program is formed, while dynamic linking is performed when the program is executed.

Advantages of static link library

a): Code loading speed is fast, and execution speed is slightly faster than dynamic link library;

b): Only It is necessary to ensure that there is the correct .lib file in the computer during development. When publishing the program in binary form, there is no need to consider whether there is a version problem with the .lib file on the user's computer. This can avoid problems such as DLL hell.

Advantages of dynamic link libraries

a) Saves more memory and reduces page swapping;

b) DLL files are independent of EXE files, as long as the output The interface remains unchanged, that is, the name, parameters, return value type and calling convention remain unchanged. Replacing the DLL file will not have any impact on the EXE file, thus greatly improving maintainability and scalability;

c) Programs written in different programming languages ​​can call the same DLL function as long as they follow the function calling convention;

d) It is suitable for large-scale software development, making the development process independent and less coupled, making it easier for different Development and testing occurs between developers and development organizations.

Disadvantages

a) The executable file generated using static linking is larger in size and contains the same common code, causing waste;

b) Applications that use dynamic link libraries are not self-complete, and the DLL modules they depend on must also exist. If dynamic linking at load time is used and the DLL is found not to exist when the program is started, the system will terminate the program and give an error message. With runtime dynamic linking, the system will not terminate, but the program will fail to load because the exported functions in the DLL are unavailable; the speed is slower than static linking. When a module is updated, if the new module is incompatible with the old module, all software that requires the module to run will be torn off. This was common in early Windows.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of What is the difference between dynamic linking and static linking in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template