Turn C experts into II

Source: Internet
Author: User

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

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.