The previous article explains the compilation and use of static link libraries under Linux, let's talk about how to compile and use the dynamic link library.
The so-called dynamic link library, that is, compile time will not really put you reference to the library into your execution program, but in the execution time will be loaded related libraries, all use this library program can share a code, the benefit is that the executable program occupies a smaller space, and, if the library needs to upgrade, You do not need to recompile your program, just upgrade the relevant library.
Let's take a look at the compilation and use of the dynamic link library, the same code as in the above, respectively, SUM.C, sum.h, and main.c, the dynamic link library file under Linux is generally called libxxx.so.
192: Zch kane$lsmain.csum. Csum. h192: Zch kane$192: Zch kane$GCC-c-fpicsum. C-------FIPC tells the compiler to compile the source code into a shared object file, and PIC (position-independent code) means the non-positional dependency code192: Zch kane$lsmain.csum. Csum. hsum. O192: Zch kane$GCC-shared-fpic-o libsum.sosum. o--------generate a dynamic-link library file libsum.so192: Zch kane$lslibsum.so main.csum. Csum. hsum. O192: Zch kane$192: Zch kane$GCC-O sumappd main.c-l. -lsum---------Generating an executable program192: Zch kane$lslibsum.sosum. Csum. OMAIN.Csum. h SUMAPPD192: Zch kane$./SUMAPPD---------Run build results Num1+ Num2 =3
Dynamic link library and static link library under Linux What the hell is that? (ii) Compilation and use of dynamic link libraries