Dynamic library Compilation:
G ++-Wall-fPIC-shared-o DataLog. so DataLog. cpp-I./-lpthread-L ../lib-llog4cpp
Among them:-shared indicates that the goal of compiling and linking is A. so dynamic library.
-FPIC is required for 64-bit platforms
Static library compilation process:
G ++-Wall-static-o DataLog. o-c DataLog. cpp-I ./
Among them:-c is only for compilation, no link options, the compilation result is a. o file
Use. o to create a static database:
Ar rscv libDataLog. a DataLog. o
From: http://blog.csdn.net/whyacinth/archive/2007/11/16/1889048.aspx
* ******************* Main options of gcc/egcs *********
Common gcc commands
Option description
-Ansi only supports the ANSI standard C syntax. This option will disable some features of gnu c,
For example, asm or typeof keywords.
-C only compiles and generates the target file.
-DMACRO defines the MACRO with the string "1.
-DMACRO = DEFN: Define the MACRO with the string "DEFN.
-E only runs the C pre-compiler.
-G generates debugging information. The GNU Debugger can use this information.
-IDIRECTORY: specify an additional header file to search for the path DIRECTORY.
-LDIRECTORY: specify an additional function library to search for the path DIRECTORY.
-Search for the specified LIBRARY when connecting to lLIBRARY.
-Msung optimizes code for 486.
-O FILE: generate the specified output FILE. Used to generate executable files.
-O0 is not optimized.
-O or-O1 optimized code generation.
-O2 is further optimized.
-O3 is further optimized than-O2, including the inline function.
-Shared object generation. It is usually used to create a shared library.
-Static prohibit the use of shared connections.
-UMACRO undefines MACRO macros.
-W does not generate any warning information.
-Wall generates all warning information.
######## Create and use a shared library #########
Special compilation and connection options
-D_REENTRANT defines the Preprocessor symbol _ REENTRANT, which activates some macro features.
-FPIC options generate code with independent locations. Because the library is transferred during running, this
This option is required because the address of the loaded memory is unknown during compilation. If
If this option is not used, the library file may not run correctly.
-The shared option tells the compiler to generate the shared library code.
-Wl,-soname-wl tells the compiler to pass the following parameters to the connector. -Soname specifies
The soname of the shared library.
# You can copy the library file to any directory listed in/etc/lD. So. conf and
Run ldconfig as root; or
# Run export LD_LIBRARY_PATH = 'pwd' to add the current path to the library search path.
The ldconfig command is mainly used to search for directories listed in the default search directory (/lib and/usr/lib) and dynamic library configuration file/etc/lD. So. conf.
Generate a shared dynamic link library (the format is as described earlier, lib *. so *) to create a dynamic loader (LD. so) the required connection and cache file. the default cached file is/etc.
/LD. So. cache. This file stores the list of dynamic link library names sorted in order.
LDD is used to show which shared libraries are required for the execution file and where the Shared Library Loading manager finds the required shared library.
Also refer to zcanoe's article http:// OS .chinaunix.net/a2007/1015/976/000000976498.shtml in chinaunix