Chapter 5
I. Thoughts on links
The target file cannot be directly executed. It must first be loaded to the linker. The linker confirms that the main function is the initial entry point (where the program starts execution), binds the symbol reference to the memory address, aggregates all the target files, and adds the library files, to generate executable files.
If a copy of the function library is a physical component of the executable file, it is called a static connection. If the executable file only contains the file name, let the loader find the function library required by the program at runtime, which is called dynamic connection.
Even in a static link, the entire libc. A file is not fully loaded into the executable file. All it loads is the required function.
The main purpose of the dynamic link library is to separate programs from the specific function library versions they use. Instead, we agree that the system will provide an interface to the program, which remains stable and does not change with time or subsequent versions of the operating system.
Advantages of Dynamic Link Library:
1. the executable file can be very small;
2. More effective use of disk space;
3. All executable files dynamically linked to a specific function library share a separate copy of the function library at runtime. The operating system kernel ensures that the function libraries mapped to memory can be shared by all processes that use them.
4. Dynamic links make it easier to upgrade the version of the function library.
Disadvantages of Dynamic Link Library:
1. The running speed is a little slower;
5.3 five special secrets linked to the function library
1. The dynamic library file extension is ". So", while the static library file extension is "."
2. For example, you use the-lthread option to tell the compiler to link to libthread. So
3. the compiler expects to find the library in the specified directory.
The default value is/usr/lib.
4. Observe the header file and determine the function library used
5. The method of extracting symbols in a static library is more restrictive than extracting symbols in a dynamic library.
Turn C experts into II