Static compilation, dynamic compilation, static Link Library, and dynamic link library

Source: Internet
Author: User

1. Static Compilation: when compiling an executable file, the compiler extracts the part of the corresponding dynamic link library (. So or. ilb) that needs to be used and links it to the executable file,
Make the executable file do not need to depend on the dynamic link library during running.

2. Dynamic Compilation: a dynamic link library must be attached to the dynamically compiled executable files. During execution, you must call the commands in the corresponding dynamic link library. So its advantage 1
This reduces the size of the execution file and accelerates compilation and saves system resources. Disadvantage 1: even simple programs only use links
One or two commands in the Library also need to be accompanied by a relatively large Linked Library. Second, if the corresponding Runtime Library is not installed on other computers, use the dynamically compiled Executable File
And cannot run.


Static Compilation:
Static lib stores the export declarations and implementations in Lib. After compilation, all the code is embedded in the Host Program.
Dynamic Compilation:
Dynamic lib is equivalent to an H file and is a declaration of the export part of the Implementation part (. dll file. After compilation, only the export declaration part is compiled into the host Program.
The corresponding DLL file is required.


Dynamic Link Library:
Create a dynamic link library that generates X. dll, X. Lib
The dynamic link library can be loaded in two ways:
1. Static Loading means loading the dynamic link library during compilation. This method can be called by class methods.
The executable program needs three files X. dll, X. Lib, and X. h to load the dynamic link library statically.
Add the following header files to the executable program:
# Include "x. H"
# Pragma comment (Lib, "x. lib ")
The library directory must be appended during compilation to prevent the program from finding X. dll during compilation.

2. Dynamic Loading
Only the X. dll file is required.
Load X. dll where the dynamic link library is required for program execution.
Then obtain the required functions or data in the X. dll library.
This method cannot call class methods.

An executable program calls a dynamic link library.


Static Link Library:
Create a static Link Library and generate the X. Lib file.
The X. Lib file and X. h file are required to call the content in the static Link Library.
The library content is directly compiled into the x.exe file.
After the executable program is compiled into x.exeusing a static database, x.exe does not need a static link library to run independently.

 

The general static compilation can be understood as loading the static Link Library; the dynamic compilation can be understood as loading the dynamic link library.
Static Link Libraries cannot contain other libraries. Dynamic Link Libraries can contain other libraries.

Static compilation, dynamic compilation, static Link Library, and dynamic link library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.