For a compiled language, compilers always have to go through preprocessing, compiling, linking and so on. As an example of C + +: The preprocessor (CPP) merges #include header files from each. c/.cpp file into the. c/.cpp file, and macros them, generating several compilation units. In general, each. c/.cpp file corresponds to a compilation unit. Subsequently, the compiler (CC) translates each compilation unit into a local binary code, and the suffix in gnu/linux is. O, suffix. obj in Ms VC. This binary code, also known as the object file, has code, data, heap, STATCK, and so on as the final destination file, but it cannot be run (missing entry points). The linker (LD) locates multiple object files in the target file, which is the process of relocate, adding additional code (other linked files) and eventually generating the target file. The destination file can be an executable file, a static link file, or a dynamically linked file.
1. The static link file in the Gnu/linux system is actually a compressed package of multiple. o files. Suppose we have cool.h cool.c and some.c files to get the static link library LIBCOOL.A. First use the following instructions to get the corresponding object file COOL.O and SOME.O:
Gcc-c COOL.C
Gcc-c some.c
The object file generated in this way is called the PDC, position-related code (position-dependence). Use the following instructions to get the static link file Libcool.a:
Ar-r LIBCOOL.A COOL.O SOME.O
Ranlib LIBCOOL.A
Static link library LIBCOOL.A compliance with gnu/linux-defined static link library Naming conventions must be "LIBYOUR_LIBRARY_NAME.A"
2. Dynamically linked files in Gnu/linux must be generated through the linker LD. Suppose we have hot.c other.c and other files to generate the dynamic link library libhot.so. First use the following instructions to get the corresponding object file HOT.O and SOME.O
gcc-fpic-c hot.c
gcc-fpic-c other.c The
parameter-fpic specifies that the generated object file is position-independent (Position-independence code), and only PIC can be used as a build dynamic-link library. Then use the following instructions to get the dynamic library:
ld-bshared-o libhot.so hot.o other.o
or the LD that can use the compiler WRAPPER:  &NBSP
gcc-shared-o libhot.so hot.o other.o You can also use the compiler to generate dynamic libraries directly:
gcc-fpic-shared-o libhot.so hot.c other.c
Here the option-shared indicates that the type of the destination file is a dynamic link library, and the naming specification for the dynamic library is "Libyour_library_ Name.so "