Http://tigcc.ticalc.org/doc/comopts.html
Source: http://www.ruchee.com/code/linux/gnu/gcc.html
Common options
-E: Only preprocessing, not compiling
-S: Compile only, not assemble
-c: Compile and assemble only, without Link
-g: Contains debugging information
-I: Specify the search directory for include files
-o: Output to the specified file name
Advanced options
-v: Detailed output of each option used in the compilation process
-C: Retained comments during preprocessing
-ggdb: Include available in the executable fileGDBDebugging information used
-fverbose-asm: The name of the C variable is used as a comment in the assembly language during compilation and translation.
-save-temps: Automatically outputs pre-processing files, assembly files, and object files. Compilation is normal.
-fsyntax-only: Only test whether the source File Syntax is correct. No compilation operation is performed.
-ffreestanding: Compiled into an independent program, not a Host Program
Language Standards
-ansi: ANSI standard
-std=c99: C99 Standard
-std=gnu89: ISO/IEC 9899: 1990 and GNU Extension
-std=gnu99: ISO/IEC 9899: 1999 and GNU Extension
-trigraphs: Supports three-character Iso c Group
Error prompt
-w: Ignore all warnings
-Werror: Warning and error are not distinguished. If any warning is encountered, compilation stops.
-Wall: Enable most warning messages
-Wshadow: A warning is issued when the block scope variable of a statement has the same name as another variable in a larger scope (this warning is not included in-WallOption, which must be enabled separately)
-Wextra: Warns of all valid but suspicious expressions
Optimization Options
-O0: Disable all Optimization Options
-O1: Level 1 Optimization. Use this option to make the executable file smaller and run faster without increasing the Compilation Time.-O
-O2: Second-level optimization, using almost all optimization technologies, this option will prolong the Compilation Time
-O3: Level 3 optimization, in-O2AddedinlineFunctions, registers, and other optimization technologies
-Os: This option is similar-O2It is used to optimize the space occupied, but does not optimize the performance. It is often used to generate the final version.
Custom Extension
-x: You can use this option to specify the custom source file extension.c,c-header,cpp-output,assembler,assembler-with-cpp,none
Van-xAll the files listed below will be treated as the specified type. To change the type, you can use-xOption, or use-x noneBack to default settings
Example:gcc -o test test.c -x assembler test.asm -x c test2.c
Creation and use of static databases
To create a static librarystatic_lib.aExample
- Compile C source file
static_lib.cWrite the function that needs to be called repeatedly, and then use the commandgcc -c static_lib.cGenerate the target filestatic_lib.o
- Use
arTool to create a static library, command format:ar rcs static_lib.a static_lib.o
- Compile C header file
static_lib.h, And the prototype declaration written to these functions
- Compile the main function
app.c, Introduce header filesstatic_lib.hIn this way, the User-Defined reusable functions can be used normally.
- Use commands
gcc app.c -static ./static_lib.a -o appCompile and generate executable filesapp
Dynamic library creation and use
To create a dynamic libraryshare_lib.soExample
- Compile C source file
share_lib.c, Write the function that needs to be called repeatedly, and then use the commandgcc -shared -fPIC -o share_lib.so share_lib.cGenerate dynamic library filesshare_lib.so
- Compile C header file
share_lib.h, Written to the prototype Declaration of the Function
- Compile the main function
app.c, Introduce header filesshare_lib.hThen, you can call the custom functions in the dynamic library.
- Use commands
gcc app.c ./share_lib.so -o appCompile and generate executable filesapp