Create a static library
Build four files Bin (executable file), Lib (library), include (header file), src (release source file)
Here's the cumming for add
Execute in src file
1) gcc-c ADD.C//compile ADD.C source file to generate ADD.O target file
2) AR crsv. /LIB/LIBADD.A ADD.O//Archive The target file *.o, generate the LIB*.A, and put the generated file in Lib
3) Gcc-o main main.c-l (Larger love dolls, the path of the library). /lib–l (Lowercase love puppet, library named Add) add–i (uppercase I): /include (Put header file)
Create a dynamic library
Gcc-fpic-c ADD.C. /include (drop header file) generate ADD.O target file
Gcc-shared-o libadd.so ADD.O generate libadd.so Dynamic Library The name of the library is add
Place this library in the Lib file of the root directory
Gcc-o Main main.c–l Add: /include (Put header file) (note the library name written here, no Lib and. So)
Dynamic library vs. static library comparison:
The dynamic library is only used for linking when it is executed.
Dynamic libraries can be used by multiple programs, so also known as shared libraries
Static libraries will be integrated in large programs, program execution is not clamped in the static library, so the static library will be cumbersome to upgrade the program, but easier to deploy
Dynamic libraries are easy to upgrade, but not easy to deploy
Using makefile
Three file bin (executable file), include (header file), src (drop source file)
Target Item Dependencies
./bin/main:./src/my_add.o./src/my_minus.o./SRC/MAIN.O//To generate an executable file for *.O files
g++./src/my_add.o./SRC/MY_MINUS.O/src/main.o-o./bin/main-i./include
./src/my_add.o:./src/my_add.cpp
g++-C/src/my_add.cpp-o/src/my_add.o-i./include//Generate MY_ADD.O
./src/my_minus.o:./src/my_minus.cpp
g++-C/src/my_minus.cpp-o/src/my_minus.o-i./include//Generate MY_MINUS.O
./src/main.o:./src/main.cpp
g++ -C/src/main.cpp-o/src/main.o-i./include//Generate MAIN.O