The static library is connected to the target code when the program is compiled, and the static library is no longer needed when the program runs. After compiling the program file large, but loading fast, isolation.
Dynamic libraries are not connected to the target code when the program is compiled, but are loaded only when the program is running, so a dynamic library exists when the program is run. Multiple applications can use the same dynamic library, when launching multiple applications, only need to load the dynamic library into memory once.
To compile a dynamic library:
-shared This option specifies to generate a dynamic connection library (let the connector generate the export symbol table of type T, and sometimes the export symbol of the weakly connected W type) without which the external program cannot connect. Equivalent to an executable file
-fpic: represents compiled to a location-independent code, without this option, the compiled code is location-dependent, so dynamic loading is a way of copying code to meet the needs of different processes, but not to achieve the purpose of real code segment sharing.
-L.: Indicates the library to be connected in the current directory
-ltest: The compiler has an implicit naming convention when looking for dynamic connection libraries, which is to precede the given name with Lib, followed by. So to determine the name of the library
To configure the library location:
Ld_library_path: This environment variable indicates that the dynamic connector can load the path of the dynamic library.
Of course, if you have root permissions, you can modify the/etc/ld.so.conf file, and then call/sbin/ldconfig to achieve the same purpose, but if there is no root permission, then only the output Ld_library_path method.
The LDD command can view the library files that the executable file relies on.
1[Email protected]:~/interview# ldd Gmedian2Linux-vdso.so.1= (0x00007fff88c71000)3Libstdc++.so.6= =/usr/lib/x86_64-linux-gnu/libstdc++.so.6(0x00007f4013945000)4Libgcc_s.so.1= =/lib/x86_64-linux-gnu/libgcc_s.so.1(0x00007f401372f000)5Libc.so.6= =/lib/x86_64-linux-gnu/libc.so.6(0x00007f4013368000)6Libm.so.6= =/lib/x86_64-linux-gnu/libm.so.6(0x00007f4013062000)7/lib64/LD-linux-x86- -. So.2(0x00007f4013c5f000)
The difference between a dynamic library (. So) and a static library (. A) under Linux