Keywords: linux; gcc; compile; link;
one. Compile and Link options:
First step: precompiling.
GCC-E Hello.c-o hello.i
-e parameter: GCC stops the compilation process after the preprocessing is complete.
The preprocessed macro definition expands into the hello.i.
Step two: Generate the target code.
Gcc-c Hello.i-o hello.o
-C parameter: Generate target code.
Compile the HELLO.I as the target code, or it can be generated directly from the source file.
Gcc-c hello.c
Step three: Link.
GCC Hello.o-o Hello
Link the generated target file into an executable file.
Can also be generated directly from the source file.
Gcc-o Hello hello.c
two. To set warning options:
1,-pedantic option: Use the extension syntax where the corresponding warning message will be generated
2.-wall option: Requires GCC to generate as many warning messages as possible
3.-werror option: Require GCC to treat all warnings as errors
three. Library Dependencies Options:
1. Linux bottom file and library file default directory:
Header file (. h):/usr/include/directory
library file (. So,. A):/usr/lib/directory
2. Common options:
-I option: Adds a new directory to GCC's header file search path.
Gcc-o Hello hello.c-i/home/crosstar/include
GCC is required to find the required header files under the/home/crosstar/include/directory.
-L Option: Adds a new directory to GCC's library file search path.
Gcc-o Test Test.c-l/home/crosstar/lib–lfoo
GCC is required to look for the required library files under the/home/crosstar/lib/directory libfoo.so
-L option: Requires GCC link library file libfoo.so.
Note: The library file naming convention under Linux:
Usually begins with a Lib three letter.
Because all library files follow the same specification, you can omit Lib three letters when you specify a linked library file name with the-l option, which means that GCC automatically links files named libfoo.so when processing-lfoo.
-static option: Force the use of static link libraries
Gcc-o Test Test.c-l/home/crosstar/lib-static–lfoo
Request GCC links when statically linked to the/home/crosstar/lib/directory LIBFOO.A