Synthesis From: http://www.cnblogs.com/javadotnet/articles/1918930.html
http://blog.csdn.net/shijinupc/article/details/6789554
CC is a very important source code compilation tool under the Linux operating system, with many important options to support the compilation of many different languages, such as C, C + +, Ada, Fortran, Objective, Perl, Python, Ruby and Java, etc. Even Linux's many kernels and many other free software and open source applications are written in C and compiled by GCC.
1. Compiling a single source file
[For example] print "Hello,linux." On the screen.
[Source code]
#include <stdio.h>
#include <stdlib.h>
int main (int argc,char **argv)
{
printf ("hello,linux.\n");
Exit (0);
}
Save the source file as hello.c and start compiling
$GCC-O Hello hello.c
After the compilation completes successfully, under the current path, generate a file named Hello, and then execute
$./hello
On the screen, you will see the results of the printing: Hello,linux.
Note: By default, after the compilation completes successfully, a file named A.out is generated under the current path, and then the $./a.out can be printed, but you can usually specify your own executable name by using the option-O.
2. Compiling multiple source files
3. Using an external function library
4. Using shared function libraries and static function libraries
5.GCC Options Detailed description
main options for 1.7.2 Gcc/egcs
table 1-3 Common options for GCC commands
option Explanation
-ansi only supports the ANSI standard C syntax. This option will prohibit certain features of GNU C,
such as ASM or typeof keywords.
-C compiles and generates only the target file.
-DMACRO defines macro macros with the string "1".
-DMACRO=DEFN defines macro macros with the string "DEFN".
-E only runs the C precompiled compiler.
-G generates debug information. The GNU debugger can take advantage of this information.
-idirectory Specifies additional header file search paths for directory.
-ldirectory Specifies additional library search paths for directory.
-llibrary searches for the specified library of libraries when connected.
-m486 code optimization for 486.
-o file to generate the specified output files. Used when generating an executable file.
-o0 is not optimized for processing.
-O or-o1 optimization generates code.
-o2 further optimization.
-o3 is further optimized than-O2, including the inline function.
-shared generate a shared destination file. Typically used when building a shared library.
-static prohibit the use of shared connections.
-umacro cancels the definition of macro macros.
-W does not generate any warning messages.
-wall generates all warning messages.
How to compile and run C programs under Linux