Introduction to libraries under Windows and Linux

  

What is a library A library file is a collection of precompiled functions that are written according to the principles of reusability. They are usually composed of a set of interrelated functions that perform a common job. In essence, a library is a binary form of executable code that can be loaded into memory by the operating system. There are a large number of libraries on both the Windows platform and the Linux platform, but because of the nature of Windows and Linux, the binary of the libraries is incompatible. Classification of Libraries There are two types of libraries under Windows: static libraries (.lib) and dynamic link libraries (.dll). There are two kinds of libraries under Linux: static libraries (.a) and shared libraries (.so). The name of the static library under Linux is generally libxxxx.a, where xxxx is the name of the lib. The name of the dynamic library under Linux is generally libxxxx.so.major.minor, xxxx is the name of the lib, and major is the major version number. Minor is the minor version number. The similarities and differences between libraries under Windows and libraries under Linux Linux shared libraries (.so) are like Windows dynamic link libraries (.dll), which contain many functions commonly used by programs. In order to facilitate program development and reduce program redundancy, the program does not need to include a copy of each commonly used function, just call the constant function in the shared library when needed. This way we call it Dynamically Linked. And sometimes we don't want to call the program to call the function of the shared library, but to link the library function code directly into the program code, that is, the program itself has a copy of the function in the shared library. This way we call it Static Linked. So, the simple difference between static libraries and shared libraries (dynamic libraries) is that the code is loaded at different times. The code of the static library has been loaded into the executable during the compilation process, so it is bulky. The code of the shared library is loaded into the memory when the executable is running. It is only a simple reference during compilation, so the code is small. The difference between the dynamic link library (.dll) under Windows and the shared library (.so) under Linux. The dll file is actually and. Like the exe file, it belongs to the executable file in PE format. For implicit reference to external symbols, the location of the external symbol needs to be written on the PE header. The PE loader will find the dependent symbol table from the PE header and load the rest of the dependencies. Dll file. This is not the case on Linux! . The so files are mostly elf executable file formats. When they need external symbols, you can not specify where these symbols are located. That is, usually. The so file itself does not know which symbols it depends on. So inside. These symbols are provided by the process that calls dlopen when it runs. We do one under Windows. You also need to carry one when you have a dll file. Lib file; in Linux, generally only need to have the corresponding header file is enough. For writing new ones. So, the symbol that can't be found can be left there until the file is finally executed to join all the required symbols together. Windows can exist one. Dl to another. The implicit dependency of dll; generally does not need to be allowed under Linux. So and. So has implicit dependencies.

Copyright © Windows knowledge All Rights Reserved