g++ command line parameters

Introduction

  1. Preprocessing [processor] => .ifile
  2. Compile [tool] => .sfile
  3. Assembler => .ofile
  4. Link [tool ld] => executable program

Detailed parameter

  • -x language filename: Set the language used in the file, make the suffix invalid, and it is valid for the following multiple. According to the convention, the suffix name of C language is .c, and the suffix name of C++ is .C or .cpp. Use to noneturn off the previous option.

Specifiable language:

c objective-c c-header c++ cpp-output assembler assembler-with-cpp none

Example :

gcc -x c hello.pig
  • -c: Only preprocess , compile , assemble and generate .o files

Example :

gcc -c hello.c
  • -S: Only preprocess and compile , generate .s file.

example:

gcc -S hello.c
  • -E: Only preprocessing is performed , files are not automatically generated, and the results can be redirected.

example:

gcc -E hello.c > pianoapan.txt
gcc -E hello.c | more
  • -o: Perform preprocessing , compilation , assembly , and linking .

example:

gcc -o hello.exe hello.c (哦,windows用习惯了)
gcc -o hello.asm -S hello.c
  • -pipe: Use pipelines to replace temporary files during compilation. When using non-gnu assembly tools, there may be some problems
gcc -pipe -o hello.exe hello.c
  • -ansi: Turn off the features in GNU C that are not compatible with ANSI C, and activate the proprietary features of ANSI C (including prohibiting some asm inline typeof keywords, and preprocessing macros such as UNIX and vax)

  • -fno-asm: This option implements ansia part of the option's function, and it prohibits using asm, inlineand typeofas keywords.

  • -fno-strict-prototype: Only works for g++. Using this option, g++ will regard functions without parameters as having no explicit description of the number and type of parameters, rather than no parameters. Regardless of whether gcc uses this parameter or not, it will think that the city has no explicit type for functions without parameters.

  • -fthis-is-varialble: It is in line with traditional C++ and can be used thisas a general variable.

  • -fcond-mismatch: Allow the type of the second and third parameters of the conditional expression to not match, the value of the expression will be voidtype

  • -funsigned-char, , -fno-signed-char, -fsigned-char: -fno-unsigned-charThese four parameters is charthe type of setting, to decide charthe type provided unsigned char(the first two parameters) or signed char(two parameters)

  • -include file: Contains a certain code, in simple terms, is to use a certain file, when another file is needed, you can use it to set, the function is equivalent to using in the code#include<filename>

example:

gcc hello.c -include /root/pianopan.h
  • -imacros file: Expand the macro of the file file to the input file of gcc/g++, the macro definition itself does not appear in the input file
  • -Dmacro: Equivalent to #define macro
  • -Dmacro=defn: Equivalent to #define macro=defn
  • -Umacro: Equivalent to #undef macro
  • -undef: Cancel the definition of any non-standard macro
  • -Idir

When you use #include"file"it, gcc/g++ will first search for the header file you made in the current directory. If it does not find it, it will return to the default header file directory. If you use the -Idesignated directory, it will first be in the header file you made. Search in the directory, and then search in the usual order.
For #include<file>, gcc/g++ will -Isearch in the specified directory, if it can’t be found, then it will search in the system’s default header file directory

  • -I-: It is to cancel the function of the previous parameter, so it is generally used -Idirlater
  • -idirafter dir: If -Ithe search fails in the directory, go to this directory to search.
  • -iprefix prefix, -iwithprefix dir: Generally used together, when -Ithe directory search fails, it will be prefix+dirsearched below
  • -nostdincMake the compiler no longer look for header files in the default header file directory of the system. It is generally used in conjunction with -I to clearly define the location of the header file.
  • -nostdin C++: It is stipulated not to search in the standard path specified by g++, but still search in other paths. This option is used in the creation of libg++ library
  • -C: When preprocessing, the comment information is not deleted. It is generally used with -E. Sometimes it is convenient to use this to analyze the program.
  • -M: Generate file-related information. Contains all the source code that the target file depends on. You can use gcc -M hello.c to test it, it's very simple.
  • -MM: Same as the one above, but it will ignore dependencies caused by #include.
  • -MD: Same as -M, but the output will be imported into the .d file
  • -MMD: Same as -MM, but the output will be imported into the .d file
  • -Wa,option: This option is passed option to the assembler; if there is a comma in the option, the option is divided into multiple options, and then passed to the assembler
  • -Wl.option: This option is passed option to the linker; if there is a comma in the option, the option is divided into multiple options, and then passed to the linker.
  • -llibrary: Formulate the library to be used when compiling

example:

gcc -lcurses hello.c # 使用ncurses库编译程序
  • -Ldir: Specify the path of the search library when compiling. For example, you can use it to make a catalog for your own library, otherwise the compiler will only find it in the catalog of the standard library. This diris the name of the directory.
  • -O0, , -O1, -O2: -O34 level compiler optimization options, -O0 indicating no optimization, -O1 default value, -O3 highest level of optimization
  • -g: It's just a compiler, which generates debugging information when compiling.
  • -gstabs: This option claims debugging information in stabs format, but does not include gdb debugging information.
  • -gstabs+: This option declares debugging information in stabs format and contains additional debugging information that is only used by gdb.
  • -ggdb: This option will generate as much debugging information as possible for gdb.
  • -static: This option will prohibit the use of dynamic libraries. Therefore, the compiled things are generally very large and can run without any dynamic link library.
  • -shared: This option will try to use the dynamic library, so the generated file is relatively small, but the system needs the dynamic library.
  • -traditional: Trying to make the compiler support traditional C language features

Guess you like

Origin blog.csdn.net/qq_29695701/article/details/95593003
Recommended