Linux application Development-Design Static library
An application
function library (user) and system call (Linux kernel)
Fenhe classification
1 Static link library (*.A)
A program uses a library of functions
2 Dynamic link library (*.so)
Multiple programs can use the same function library to reduce the size of the program
3 Static cubby Dynamic Library Large
Three make your own static library
1 gcc-c mylib.c-o MYLIB.O
2 ar cqs LIBMYLIB.A mylib.o
3 Copy the good LIBMYLIB.A to the/usr/lib directory
iv using a static library of your own creation
1 Linux default link dynamic library, to link to a static library: gcc-static Hello.c-o helloc.out
2 Use your own dynamic library:
Create a main.c to call your own library
Create a prototype declaration of a function inside the main.h that contains the function library to be called
Compile call Gcc-static-lmylib main.c-o main.out-l parameter for calling your own Lib
When GCC links, only the C function library is linked by default, and for other libraries, you need to use the-l option to indicate that a link needs to be displayed.
Linux directory/usr/lib and/lib stored in the corresponding LIB, commonly used LIBMYLIB.A to name, the front Lib must be added
Five simple addition calculator case List
1 Writing ADD.C
2 compile into Static library: gcc-c add.c-o add.o ar cqs libadd.a add.o
3 Copy to/USR/LIB:CP libadd.a/usr/lib/
4 Create MAIN.C to call the Add function as the main function to create a main.h to contain the declaration of the Add function
5 Compile and debug: Gcc-static-ladd main.c-o main.out
6 run./main.out
Linux application Development-Design Static Library