The making of shared Library under linux and its Common problems
Generate a shared library from a linked list written by yourself
1, compilation
2. Set the library name:
The name format of the library: lib + XXX + version number .so (library name is XXX)
-shared generates a shared file library-fpic dynamic link
3, put the header file and .so file in the system directory
(using shared libraries, change the previous # include "list.h" to # include
< list.h >Delete the list.* in this folder and run it successfully)
4. Link library: gcc main.c-o main-lList
Note: if .h is not placed under the system path, use the-I path
If .so is not placed under the system path, use the-L path
If the shared library is not placed under the system path, how to solve the problem that cannot be found at run time
1) first, move .h and .so to a non-system path and link to generate an executable file that cannot be found at run time:
2) solution 1: modify the shared library configuration file / etc/ld.so.conf to add the path of .so to the configuration file; execute: ldconfig
solution 2: configure the environment variable LD_LIBRARY_PATH
(however, this method is temporary and only valid for the current user this login)
You can also view the value of the environment variable: $LD_LIBRARY_PATH
Then modify it, LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/mnt/hgfs/share/