The library, in essence, is a library function that we use when we program, so we can avoid repeating this code. such as: standard input and output functions in C/s + +, we are using their library;
The static library is when we compile our functions, directly to the library to be used to compile the content of the inclusion, so that they become one, and the dynamic library, we compile our function is not directly to use the contents of the library to be included in, but to run the time to call it, as for their shortcomings, It is clear to think with your mind.
Static libraries:
Use. A as suffix, meaning archive file; Static library is obtained by command ar; command ar to pre-process, compile, and compile the source code. o files can be contained by multiple. o files;
For example, when we write the C program, it will default to include the C standard library/USR/LIB/LIBC.A, which has ans1/iso standard specified functions, such as printf. So we do not have to manually link, if you use a function other than the standard specified function, then we have to manually link the relevant library, such as the Mathematical Static library Libm.a (header file is math.h)
Command of AR:
later supplemented;
/****/
Example: Write a libhello.a static library below, and then call through the MAIN.C function;
Writing hello.h
void hello ();
Writing hello.c
#include <stdio.h>"hello.h"void hello () { printf ( " Hello, world\n. " );}
Generate hello.o Target file
gcc -o hello.o-c hello.c
Generate LIBHELLO.A Static Library
ar -cqs libhello.a hello.o
Edit Main.c File
" hello.h " int Main (intChar* * argv) { hello () ; return 0 ;}
Now use the static library to generate the final executable code for the MAIN.C:
Gcc–o out MAIN.C libhello.a
Run the code to see the results:
./ Outhello,world!
Dynamic libraries:
Static libraries and dynamic libraries under Linux