Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between dynamic links and static links in linux

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is the difference between dynamic links and static links in linux". In daily operation, I believe that many people have doubts about the difference between dynamic links and static links in linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what is the difference between dynamic links and static links in linux". Next, please follow the editor to study!

Differences: 1, the static link is carried out before the formation of the executable program, while the dynamic link is carried out when the program is executed; 2, the code loading speed of the static link library is fast, the execution speed is slightly faster than the dynamic link library; 3, compared with the dynamic link, the executable file generated by static link is larger.

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

Dynamic Link and static Link in linux

The process of compiling links

Compilation is divided into three steps. First, the source file is preprocessed. This process mainly deals with some commands or statements defined by # (such as macro, # include, precompiled instruction # ifdef, etc.) to generate * .I files. Then it compiles, mainly for lexical analysis, syntax analysis and semantic analysis, etc., to generate * .s assembly files. Finally, the assembly process is relatively simple, that is, the corresponding assembly instructions are translated into machine instructions to generate relocatable binary object files.

Two ways of linking

Static link

Dynamic link

The biggest difference between static links and dynamic links is that the timing of links is different. Static links are carried out before the formation of an executable program, while dynamic links are carried out when the program is executed.

Advantages of static link libraries

A): code loading speed is fast, execution speed is slightly faster than dynamic link library

B): you only need to make sure that you have the correct .lib file in the development of this computer, and then you don't need to consider whether there is a version problem with the .lib file on your computer when you publish the program in binary form, and you can avoid problems such as DLL hell.

Advantages of dynamic link libraries

A) more memory savings and less page swapping

B) the DLL file is independent of the EXE file, and as long as the output interface remains unchanged, that is, the name, parameter, return value type and calling convention remain unchanged, replacing the DLL file will not have any impact on the EXE file, thus greatly improving the maintainability and expansibility

C) programs written in different programming languages can call the same DLL function as long as they follow the function calling convention

D) suitable for large-scale software development, making the development process independent, less coupled, and convenient for development and testing between different developers and development organizations.

shortcomings

A) the executable files generated using static links are large and contain the same common code, resulting in waste

B) the application that uses the dynamic link library is not self-complete, and the DLL module it depends on also exists. If you use dynamic link at load time, when the program starts, it finds that DLL does not exist, and the system will terminate the program and give an error message. With dynamic linking at run time, the system will not terminate, but the program will fail to load because the export function in DLL is not available; it is slower than static linking. When a module is updated, if the new module is not compatible with the old module, then all the software that needs the module to run will be torn up. This was common in early Windows.

At this point, the study on "what is the difference between dynamic links and static links in linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report