Sharing code can improve efficiency, but for code security, for reasons like this, it is generally rare to keep C files, instead of compiling C files into. o files,
Shared code is implemented by sharing h files and. o files.
Multiple. o files are cumbersome to manage, and if you package these files into a library, it is a common method to call the functions inside through the link library.
It is generally divided into static libraries (archives) and dynamic libraries.
Create an archive
The archive is a static library in the form of libxxx.a. You can use the AR command to create an archive
Ar-rcs libxxx.a a.o b.o ...
At this point, A.O and B.O are packaged in a static library of LIBXXX.A
Use:
<1> put LIBXXX.A in a standard directory
At this point, you can link the library without specifying the path to the library file gcc-lxxx
<2> put libxxx.a in a directory of your own set
At this point, you need to specify the library directory Gcc-l/path/-lxxx
Create a dynamic library
gcc-shared x.o-o libxxx.so (Linux or Unix) Libxxx.dylib (MAC)
Use the same method as the static library.
Static libraries and dynamic libraries for C-language shared code