"Static links and dynamic links"
Static links: After the source program compiles, if you want to execute, first link to the target file, if executed after the link is completed, load the link well into the memory
Disadvantages:
<1> If a target file is reused, the target file will be loaded into memory each time, resulting in waste;
<2> If updates are made relative to a target file, the target file needs to be recompiled + linked and then re-loaded into memory.
Dynamic Links : The target file is loaded into memory and then compiled into an executable file after the program starts running (loaded into memory)
Advantages:
<1> can avoid multiple links to memory for the same target file;
<2> update a target file to directly overwrite the new target file, and do not compile again.
[plugin]:
The dynamic link is implemented when the program is run, which extends the function of the program.
such as the development of a browser, the browser provides the interface of the program (packaged good compiled target file (binary)), a third-party company downloaded our interface after the import into an IDE after the new project began to develop, Based on our API documentation, they developed a skin-changing plugin (by implementing the method in the class library), which the IDE provides to the source program for some syntax checking, but still needs to compile, and compile successfully we upload to the server. After users download to the local, you need to restart the browser (run), and then download the plugin is detected, start and browser class library link, and the browser class library and the System class library link, so that the new plug-in can be loaded into virtual memory, after initialization, you can see just the plug-in began to run.
[appearance of software]
The operating system provides some basic runtime libraries, such as input and output, which are compiled but not linked binaries. O/.obj;
When the user uses the IDE to develop the software, the integrated environment provides the corresponding class library, such as the C standard class library, which is a part of the Basic Runtime library packaging;
Class Library provides the interface of the class and method, we implement the interface to implement the function, but the class library compiled by different compilers is mostly incompatible;
For others to write well compiled Jar class library We can import into the project, this is because Java first compiled according to the class library as the intermediate code, class library and platform-independent;
In the development process, the runtime will provide us with a set of API documentation, the role of the identification class in the document and the method of implementation;
If we call the relevant method directly in this class error, because the compile time, access permissions so that the class can not directly access the class library;
So if you want to use the integrated environment to provide/customize the class library, you have to import the include or introduce import, so as to access;
When we have developed the software, start compiling: The compilation system will compile the current source code into a binary segment file, at this time and the external class has not established a connection;
Two types of linking scenarios:
<1> [Static link]: The method of this class invokes the method (API) of the corresponding class in the imported class library, and these methods perform some of their own operations first;
The following operations invoke the system-provided APIs and some auxiliary libraries to implement basic system operations, all of which are essentially elf/pe files in the system library/library/C standard library, and when the link is sorted/paged into the application's virtual memory.
[Execution] The virtual memory is established and the physical memory is mapped, and the CPU starts executing.
<2>[execution]
[Dynamic link]: Compiled source files and system libraries/auxiliary libraries the/C standard library starts the link after it runs, that is, when a library is needed after it has started, we then link the library to virtual memory and check the virtual memory for the existence of the library when linking to virtual memory. If it exists, no more links are used directly to the existing library.
[Real execution]: virtual memory setup and physical memory mapping, the CPU starts to execute.
[Note]: virtual memory is not mapped to real physical memory, it is only a segment of the application in the corresponding 0-based memory address, when the beginning of the run, the virtual memory paging method to establish the virtual memory to the physical memory mapping, then the program is really running.
[Note]: The library file is still present after compilation, and the process of linking is the process of calling the library file and then invoking the system API in the compiled file. A static link must first be linked (initialized) to become an executable file, and the dynamic link begins to be linked (initialized) at execution time, and the dynamic link is inevitably lost for a while, but adds less space and flexibility.
Diary of C-static links and dynamic links