Article Title: Build and use a Linux library. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In this article, we will explore knowledge related to Linux libraries. First, we will examine the basic knowledge of the static library and introduce how to use the ar command to create a static library. Next, we will learn about the shared library and describe the content of the shared library that can be dynamically loaded.
1. What is a library?
In general, a library is a collection of target program files. If some target files provide the functions required to solve a specific problem, we can merge these target files into a library so that application developers can access these target files more easily, save searching everywhere.
For static libraries, we can use the utility ar to create them. When application developers use the library for program compilation and connection, the components required for the application in the library will be integrated into the final executable program. Later, because the library has been integrated into the application image and become an inseparable part of it, there is no external library for the application.
The shared library (or dynamic library) is also connected to an application image, but two different steps are required. The first step occurs when an application is built. The linked program checks whether all the symbols (function name or variable name) required to build the application are found in the application or library ). The second step occurs at runtime. The dynamic loader loads the required shared library into the memory and dynamically links it to the application image. Note: Unlike static libraries, the components in the shared library are not put into the application's image this time. Obviously, the generated application image is small because the shared library and application image are independent of each other, as shown in.
Static Library
Dynamic library
Although shared libraries can save memory, this is costly-the library must be parsed at runtime. Obviously, it will take some time to find out which databases are needed, search for these databases, and load them into the memory.
In this article, we will create two libraries, a static library and a dynamic library, and apply them to the program in their respective ways to experience the difference between the two.
[1] [2] [3] [4] [5] Next page