LinuxC programming (1) -- database file -- general Linux technology-Linux programming and kernel information. The following is a detailed description. Library files are a collection of pre-compiled functions, which are all written in accordance with reusable principles. They are usually composed of a group of interrelated functions used to complete a common task. For example, a function (curses Library) used to process Screen Display
Standard System library files are generally stored in/lib or/usr/lib subdirectories. During compilation, you must tell the C language compiler (more specifically, the linked program) which library files should be searched. By default, it only looks for standard library files in C language. This is a problem left over from the time when the computer speed is slow and the CPU price is very expensive. At that time, it was impractical for the compiler to put a library file in a standardized subdirectory and send it to the compiler. Library files must comply with certain naming rules, and must be explicitly given on the command line.
The library file name will always start with the letters lib, followed by a description of the function library (for example, c indicates that this is a c language library, and m indicates that this is a mathematical library ). The last part of the file name starts with a period (.), and the type of the library file is given as follows:
●. A traditional static function library.
●. So and. sa shared function libraries (see the following description ).
The function library is generally divided into two formats: static and shared. You can check them with the ls/usr/lib command. When notifying the compiler to find a library file, can the compiler provide its complete path name or use it? L flag.
1. Static Library
The simplest form of a function library is a set of binary target code files that can be "used as needed. When a program needs to use a function in the function library, it will reference the header file declared for this function through the include statement. The compiler and the linked program combine program code and library functions to form an independent executable program. If you are not using a standard C Language Runtime Library but an extension library, you must use it? L option.
Static libraries are also called archives. Their file names end with. a by convention. For example, the C standard library is/usr/lib/libc. a, and the X11 library is/usr/X11R6/lib/libX11.a.
It is not difficult to build and maintain a static database by yourself. You can use the ar ("create a file") Program. Note that, the gcc-c command should be used to compile the functions separately. Try to save the functions to different source code files. If functions need to access common data, they can be put in the same source code file and used to declare static variables.
2. Shared Library
The disadvantage of the static library is that if we run multiple programs at the same time and they all use functions from the same function library, there will be many copies of the same function in the memory, and many copies of the same function in the program file itself. This consumes a lot of valuable memory and hard disk space.
Many UNIX systems support shared libraries and overcome unnecessary consumption in both aspects.
The storage location of the shared library is the same as that of the static library, but it has different file suffixes. On a typical Linux system, the shared version of the C standard library is/usr/lib/libc. so N, where N is the main version number.
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