[Country EMBED strategy] [073] [Static function library design]

Source: Internet
Author: User

External functions

The external functions required in the design of Linux applications are mainly provided by libraries and system calls.

Difference between the two

System calls in the Linux kernel are located in a kernel mindset, while the library is provided by the engineer in the user state

Function Library Classification

function library can be divided into static function library and dynamic function library according to link way

Storage location

The main libraries used by Linux applications are stored in the/lib,/usr/lib directory, where the dynamic function library is named *.so.*, and the static function library is named *.A.

Features of the static link library

The library function code to be used by the program is copied to the program at the time of the link. If there are multiple processes running in memory at the same time, and using the same library, then there will be multiple copies, which is a waste of space.

Using the static function library

When linking under 1.Linux, the default is the dynamic-link library

2. If you need to use a static library, you need to use the compile option-static

Example: gcc–static hello.c–o Hello

Making a library of static functions

1. Compile into intermediate file gcc–c Mylib.c–o mylib.o

2. Packaged into a static function library ar cqs LIBMYLIB.A mylib.o

3. Copy the prepared LIBMYLIB.A into the/usr/lib

Using the static function library

-LNAME:GCC when linking, only the C function library is linked by default, and for other libraries, you need to use the-l option to indicate that a link needs to be displayed.

Example: Gcc–hello.c–lmylib–o Hello

[Country EMBED strategy] [073] [Static function library design]

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.