GCC parameter notes

xiaoxiao2021-03-06  86

[Declaration] This document is my note about GCC parameters. I miss the DOS era. I use a small book, record all the parameters of all DOS commands. Haha, the following things may not be very comprehensive, I will refer to a lot of books. And the help of GCC. The reason for incompleteness is that I haven't seen this parameter yet, another reason is that I may not use it, I will slowly make up. Haha if you want to turn In this article, please keep my email (pianopan@beeship.com) and the fullness of the article. [Introduction] GCC and G is the GNU's C & C compiler GCC / G when performing compilation, you need 4 steps. 1. Preprocessing, generates .i file [Preprocessors CPP] 2. Pretreatment CPP] 2. Do not convert the pre-processed file into assembly language, generate files. S [Compiler EGCS] 3. There is a compiled change to target code (machine code) Generate .o file [assembler as] 4. Connect the target code, generate the executable [LED] [Parameter Details] -x language filename Set the language used by the file, so that the column is invalid, Multiple valid. That is, according to the surfix name of the convention C language is .c, and C suffix name is .c or .cpp, if you are very personal, determine your C code file's suffix name is .pig haha, Then you have to use this parameter, this parameter works on the files behind him unless the next parameter is used. The parameters you can use have these `c ',` Objective-c', `c-header ',` C ', `cpp-output ',` assembler', and `assembler-with-cpp '. See English should be understood. Example usage: gcc-x c hello.pig -x none filename turned off the previous option, that is, let GCC automatically identify file type example usage: gcc-x c hello.pig -x none hello2.c - c only activate pretreatment, compile, and compile, that is, he only makes the program into an OBJ file example usage: gcc -c hello.c He will generate .o Obj file -s only activates pre-processing and compile, means The file is compiled into assembly code. Example GCC -S Hello.c He will generate .S assembly code, you can use the text editor to view -e only activate pre-deputation, this does not generate files, you need to redirect it to an output file. Example usage : Gcc -e hello.c> Pianoapan.txt gcc -e hello.c | more slowly, a Hello Word also develops a target name with code -o processing to 800 rows, is default, GCC compiled The file is a.out, it is difficult to listen, if you have the same feeling, change it, haha ​​example gcc -o hello.exe hello.c (Oh, Windows habit) gcc -o hello.asm -s Hello .C-PIPE uses pipes instead of compile temporary files, when using non-GNU assembly tools, maybe some questions may be gcc -pipe -o hello.exe hello.c-ANSI closes the characteristics of incompatibility with ANSI C in GNU C, activation ANSI C's proprietary feature (including some ASM inline typeof keywords, and UNIX, VAX and other pre-processing macros, -fno-asm This option implements a part of the function of the ANSI option, which is forbidden to use ASM, Inline and TypeOf as a key word.

-fno-strict-prototype works only to G , using this option, G will be a function that does not have parameters, it is considered that there is no explicit to the number and type description of the parameters, not without parameters. And GCC does not With this parameter, you will have a function without parameters. It is considered that the city has no explicitly instructions. The second and third parameter types do not match, the value of the expression will be the four parameters of the VOID-funsigned-char-fno-signed-char-fsigned-char-fno-unsigned-char-fun-char to set up the char type, decided Set the char type to unsigned char (the first two parameters) or Signed char (the latter two parameters) -include file contains a code, simply, when you use a file, you can need another file. With it, the function is equivalent to using a #include example usage in the code:

GCC Hello.c -inClude /Root/pianopan.h

-imacros file

The macro of the file file is extended to the GCC / G input file, the macro definition itself does not appear in the input file

in

-Dmacro

Equivalent to C language #define macro

-Dmacro = DEFN

Equivalent to C language #define macro = defn

-Umacro

Quite in the C language #undef macro

-undef

Cancel the definition of any non-standard macro

-IDIR

When you use a #include "file", GCC / G will look for the heads you make in the current directory.

Document, if not found, he returns to the default header file directory, if you use -i to make a directory, he

I will look for the directory you have developed, and then look at the regular order.

For #include

GCC / G will look for the directory set by -i, find can't look up, and then

Default header file directory lookup

-I-

It is the function of canceling the previous parameter, so it is generally used after -idir.

-idirafter Dir

Find failed in the -i directory, telling this directory to find it.

-IPRefix Prefix

-iwithPRefix Dir

Generally used, when the -i directory looks failed, look for prefix dir

-nostdinc

Make the compiler no longer the system default header file directory to find the header, generally and -i joint use, clear

Limited the position of the header file

-NostDin C

The standard roads not specified in G are searched in other paths, but they are created in other paths.

Libg library

-C

When pretreatment, do not delete the comment information, generally and -e use, sometimes analyze the program, use this very

convenient

-M

Generate the information associated with files. All source code depends on the target file

You can use gcc -m hello.c to test it, it is very simple.

-Mm

The same as the above, but it will ignore from #include

Resulting dependency.

-Md

Same as -m, but output will be imported into .d.

-Mmd

Same as -mm, but output will be imported into .d.

-WA, Option

This option passes the Option to the assembler; if there is a comma in the Option, you divide the option into multiple elections.

Item, then pass to the assembler

-Wl.option

This option passes the Option to the connection program; if there is a comma in the Option, you divide the option into multiple elections.

Item, and then pass to the connection program.

-llibrary

Formulate the library when compiled

Example usage

gcc -lcurses Hello.c

Compile using NCURSES library

-Ldir

When developing compilation, search the path of the library. For example, your own library, you can use it to formulate a directory, otherwise

The compiler will only find it in the directory of the standard library. This DIR is the name of the directory. -O0

-O1

-O2

-O3

4 levels of the optimization options for the compiler, -O0 indicate that there is no optimization, -o1 is the default value, the -O3 optimization level is the most

high

-g

Just the compiler, when compiling, the generating strip is information.

-gstabs

This option claims to debug information in a Stabs format, but does not include GDB debugging information.

-gstabs

This option claims to debug information in a Stabs format and includes additional debugging information for GDB.

-ggdb

This option will generate the debugging information of GDB as much as possible.

-static

This option will prohibit the use of dynamic libraries, so it is generally very large, no need.

Dynamic connection library can run.

-Share

This option will try to use dynamic libraries, so generate files are relatively small, but the system needs to be generated by dynamic libraries.

-traditional

Try to make the compiler support the traditional C language characteristics

[Reference]

-Linux / UNIX Advanced Programming

Zhongke Hongqi Software Technology Co., Ltd. Edited. Tsinghua University Press Publishing

-Gcc man Page

[Changelog]

-2002-08-10

Ver 0.1 releases the original document

-2002-08-11

Ver 0.11 Modify Document Format

-2002-08-12

Ver 0.12 joins the parameters for static libraries, dynamic libraries

-2002-08-16

Ver 0.16 adds 4 phases of GCC compilation

转载请注明原文地址:https://www.9cbs.com/read-108680.html

New Post(0)