Gnu Compiler Collection(GCC)

Four steps:
1) preprocess: deal with #define, #ifdef, …, to do some macro substitution.
2) compile: generate assembly file.
3) assemble: generate machine code file (relative to CPU and OS).
4) link: find symbol and shared object from library, generating executable object.

When we write:

$ gcc xxx.c

gcc calls cpp, cc1, as, ld, respectively to complete these four jobs.

Important Flags

-c: Only create object file.
-S: Only create assembly file.
-g: Generate some debug information when compiling, for debug tools like gdb, ddd.
-o: Give a name for the crated binary object, because default name is a.out
-D: Conditional compile,relative to #ifdef and #define. If defined, then compile.
-W: Specify condition for showing warning. Wall shows all warning.
-L: Add a new directory for searching library.
-I: Add a new directory for searching header file (*.h)
-l: Add a new library. Original gcc only uses the library libc.
-O1 -O2 -O3: Optimization. Need more time.

Example

$ gcc -c -o test.o test.c
$ gcc -S -o test.s test.c
$ gcc -g -o test.o test.c
$ gcc -D_SOLARIS_ -o test test.c
$ gcc -Wall -L./lib/ -I./include/ -o foo.o foo.c
$ gcc -Wall -L../lib -I../include -lX11 -lXext -lm -o xprog xprog.c
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License