I often use gcc or g++ to compile code, but I often cannot remember some compilation parameters. I will record them here.
Several stages of compiling code: preprocessing - compilation - assembly - linking
Preprocessing: expand macros, header files.
Compile: Check the syntax and compile it into an assembly file if there is no problem.
Assembly: Compile assembly files into object files.
Link: Link the target files.
Commonly used parameters
-ansi only supports ANSI standard C syntax. This option will disable certain features of GNU C, such as the asm or typeof keywords.
-c Only compile and generate object files.
-DMACRO Defines the MACRO macro with the string "1".
-DMACRO=DEFN Defines the MACRO macro with the string "DEFN".
-E only runs the C precompiler.
-g Generate debugging information. The GNU debugger can exploit this information.
-IDIRECTORY Specifies additional header file search path DIRECTORY.
-LDIRECTORY specifies additional library search path DIRECTORY.
-lLIBRARY searches the specified function library LIBRARY when connecting.
-m486 Code optimization for 486.
-o FILE Generate the specified output file. Used when generating executable files.
-O0 does not perform optimization processing.
-O or -O1 optimizes generated code.
-O2 further optimization.
-O3 is further optimized than -O2, including inline functions.
-shared generates shared object files. Usually used when building shared libraries.
-static disables the use of shared connections.
-UMACRO Undefines the MACRO macro.
-w does not generate any warning messages.
-Wall generates all warning messages.
reference:
https://blog.csdn.net/technologyleader/article/details/125495452