Relationship between C ++ static library and dynamic library, static dynamic
What is a database?
Libraries are existing, mature, and reusable code.In reality, every program depends on many underlying libraries. It is impossible for everyone to start from scratch. Therefore, the existence of libraries is of extraordinary significance.
Static and dynamic means links. Review the steps for compiling a program into an executable program:
Static Library:
The reason for becoming a [static library] is that, in the Link stage, the target file. o generated by the Assembly will be linked together with the referenced library and packaged into the executable file. Therefore, the corresponding link method is called static link.
If the static library and the target file generated by the Assembly are linked to executable files, the static library must be in the same format as the. o file. In fact, a static library can be simply viewedA group of target files (. O/. objFile ).That is, a file formed after many target files are compressed and packaged. Summary of static database features:
1. the link of the static library to the function library is completed during the compilation period.
2. The program is no longer related to the function library during runtime, which facilitates transplantation.
3. space and resources are wasted because all related target files and the function libraries involved are linked to form an executable file.
Through the above introduction, it is found that static libraries are easy to use and understand, and code reuse is also achieved. Why dynamic libraries?
Why do I need a dynamic library?
Why dynamic databases are required is actually caused by the characteristics of static databases.
1. Space waste is a problem with static databases.
2. Another problem is that the update, deployment, and release pages of the static library may cause problems. If the static library liba. the lib is updated, so all applications that use it need to be re-compiled and released to the user (for players, it may be a small change, but it causes the whole program to be re-downloaded,Full update).
The dynamic library is not connected to the target code during program compilation, but is loaded only when the program is running.If different applications call the same library, only one instance of the shared library is required in the memory.To avoid space waste. The dynamic library is loaded only when the program is running. It also solves the trouble of updating, deploying, and publishing pages of the static library. You only need to update the dynamic library,Incremental update.
Summary of dynamic database features:
1. The dynamic library delays loading links to some library functions until the program is running.
2. You can share resources between processes. (Therefore, a dynamic library is also called a shared library)
3. upgrade some programs.
4. Even link loading can be fully controlled by programmers in program code (Show call).