This article according to Http://topic.csdn.net/u/20091026/10/0e913e37-e4a2-4504-bcc7-61af18a22dde.html?6487 's reply summarizes.
1. Shared Library
Often made into a shared library, when the-shared parameters, and the link generated file name libxxx.so, can be placed under/usr/lib
When other programs refer to the library, add-lxxx to the link.
After you edit the code, use a command similar to the following at compile time to generate a shared library (if the source file is MYFUN.C):
gcc-shared-fpic-wmyfun.c-0 libmy.so
Explanation:-shared generates shared libraries;
-FIPC denotes "position-independent code" (Position independent), which is not added;
-W indicates an output warning message, which is not added;
The name of the library file should be in libxxxx.so format;
To reference this library:
GCC xxx.c-0 xxx.out-lmy
-L indicates that the library to be connected is set (libmy.so, and I can be lost)
2. Static Library
FileName: LIB.C
First compile into target file Gcc-o mylib.o-c LIB.C
The static library is then created to place the MYLIB.O in the LIBMYLIB.A ar RCS LIBMYLIB.A MYLIB.O
Finally copy to the library directory/usr/lib CP LIBMYLIB.A/USR/LIB/LIBMYLIB.A
The function that is called directly at the time of writing is, just add the-l option after compiling to follow the library name
such as Gcc-o test Test.c-lmylib//mylib is the name of the library created earlier
3. Dynamic Library
Creation is Gcc-fpic-share-o mylib.so LIB.C
Calls are also divided into two ways
One way is to Gcc-o test test.c./libmylib.so (Note that this is the path to the dynamic library)
The second method is to use the functions of a dynamic library. You man dlopen look at those functions and you'll know it's not much to say.