Create a static library
Build four file Bin (executable file), Lib (library), include (header file), src (release source file)
Here's the cumming for add
Run 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 folder
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 cubby comparison:
Dynamic libraries are linked only when they are running
Dynamic libraries can be used by multiple programs, so also known as shared libraries
The static library will be integrated in the large program, the program run is not sandwiched in the static library, so the static library will be cumbersome to upgrade the program, but easier to deploy
Dynamic libraries facilitate upgrades, 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//Generate a *.O file to run the file
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
Simple version
Build a simple Makefile
1) Vim Makefile
2) Main.exe:main.cpp
g++ $^-o [email protected]
3) Make
[Email protected] is the target item, $^ is the dependency
When makefile is a lot more
Make-f Make.my_read Select a specific make.my_read run