1 Linux Dynamic Static library is what.
Some code is born into a code package for other programs to call, that is, dynamic static library. Static and dynamic libraries are not executable files, but are compiled from source files.
Linux, the static function library (corresponding to the. a file), the Shared function library (dynamic library, corresponding to the. so file).
The. A file is similar to a Windows. dll file (Dynamic Link Library), which is analogous to Windows. File. o files, which are equivalent to. obj files in Windows.
2 The difference between dynamic and static library
Static libraries and dynamic libraries are two ways to share program code, and the difference is:
(1) The static library is copied to the target program code in the link phase of the program, and the static library is no longer needed when the program is running.
(2) Dynamic Library in the link phase, and will not be linked to the target program code, but the program at run time by the system dynamically loaded into memory for the program calls, so the program is also required to run the existence of a dynamic library.
The advantage of using dynamic libraries is that the system only needs to load one dynamic library at a time, and different programs can get copies of the same dynamic libraries in memory, thus saving a lot of memory.
3 Use of the library
If the library name libsomething.a, link, plus the compilation option-lsomething.
For example, the math library is LIBM.A, and the compilation option is-LM.
4 generation of Linux library files
(1) Generate. So file:
$GCC test_a.c Test_b.c-fpic-shared-o libtest.so
$GCC test.c-l.-ltest-o Test
-shared Specify build dynamic link library
-fpic represents code that is compiled as location-Independent
-L. Represents the library to be connected under the current directory
-ltest compiler has implied naming rules when looking for dynamic connection libraries
The. So file is also a file in elf format.
$GCC-G-fpic-c src.c-o LIBSRC.O
$GCC-G-shared-wi,-soname,libsrc.so-o libsrc.so libsrc.o-l<?
(2) generate. A file
$GCC-O fun.o fun.c
$ar-RC Fun.a FUN.O