参考资料:
http://www.linuxidc.com/Linux/2012-01/50739.htm
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
1.
-fpic
Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that-fpicdoes not work; in that case, recompile with-fPICinstead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The x86 has no such limit.)
Position-independent code requires special support, and therefore works only on certain machines. For the x86, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.
这是编译器选项
2.
-shared
Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options used for compilation (-fpic,-fPIC, or model suboptions) when you specify this linker option.
这是链接器选项
3.
dlfcn.h (对应的.a文件是libdl.a, 因此你在链接的时候要加上 -ldl)
这个头文件包含了 dlopen, dlsym, dlclose, dlerror 等等与动态链接库操作相关的函数
类似于Windows 中的 LoadLibrary, GetProcAddress 等等
4.