GCC parameter details

xiaoxiao2021-03-06  37

UNIX System Development -gcc arguments detailed http://www.chinaunix.net Author: sdccf Posted: 2004-01-02 21:37:44

[Version] -0.13 [Declaration] This document is my note about gcc parameters. I miss the DOS era. I use a small book, record all DOS command parameters. Haha, the following things may not be very comprehensive, I Refer to lots of books, and GCC help. If the reason is that I haven't seen this parameter yet, the reason is that I may not use it, I will slowly make up. Haha If you want to turn in this article, please keep the comprehensiveness of my email (pianopan@beeship.com) and article. [Introduction] GCC and G is the GNU's C & C compiler GCC / G when performing compilation work, 4 steps 1. Pretreatment, generate .i file [Preprocessor CPP] 2. Pretreatment files do not convert the pre-processed files into assembly language, generate files. S [Compiler EGCS] 3. Subcombinations become targets Code (machine code) generated. Own file [assembler as] 4. Connect the target code, generate the executable [LED] [Parameter Details] -X Language FileName Set the language used by the file, make the retrore name invalid For future multiple valid. That is, based on the suffix name of the convention C language is .c, and C suffix name is .c or .cpp, if you are very personal, decide that your C code file is the suffix name. Pig Haha, then you have to use this parameter, this parameter works on his file name, 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 the pipeline instead of the temporary file, when using a non-GNU assembly tool, some questions may be gcc -pipe -o hello.exe hello.c -ansi to close the characteristics of incompatible 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 type -funsigned-car -fno-signed-char-fsigned-char -fno-unsigned-char, which is set to 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 your code: gcc hello.c -include /root/pianopan.h -imacros file will expand the macro of the File file to GCC / G input files Macro definition itself does not appear in -Dmacro equivalent to C language #define macro -dmacro = DEFN equivalent to C language #define macro = defn -umacro equivalent to C language #undef macro -undef Cancel the definition of any non-standard macro-Edir when you use #include "file", GCC / G will first find the header file you set in the current directory. If you don't find it, he returns to the default header file. Looking for the directory, if you have set the directory using -i, he will look for the directory you have developed, then go to the regular order. For #include , GCC / G will go to the directory to the -i to find, Finding, then finding the default header file directory to the system - i- is the function of canceling the previous parameter, so it is generally used after -idir after -idirafter Dir in the -i The lookup failed in this directory. -Iprefix prefix -iwithprefix Dir is generally used, when the directory lookup fails, will find -nostdinc to find -nostdinc to default, the compiler is no longer system default header file directory. Looking for header files, generally and -i-i-use, clearly defining the position of the header file - NostDIN C specifies the search in the standard road specified by G , but still search in other paths, this option is in the libg library Used -c When preprocessing, the annotation information is not deleted, generally and -e use, sometimes analyzing the program, with this very convenient -m generated file associated. All source code depends on the target file You can test it with gcc -m hello.c, very simple. -Mm and the above, but it will ignore the dependencies caused by #include .

-Md and -m are the same, but the output will be the same as the file imported to .d and -mm, but the output will be imported into .d -Wa, Option This option passes the Option to the assembler; if there is Option Command, divide Option into multiple options, then pass to the assembler -wl.option This option passes the Option to the connection program; if there is a comma in the option, the Option is divided into multiple options and then passed to the program. LLIBRAR is used to use the library example GCC -LCURS HELLO.C to use the NCURSES library compiler - LDIR to search the path. For example, your own library, you can use it to create a directory, otherwise the compiler will only look at the directory of the standard library. This DIR is the name of the directory. The 4 levels of the optimization options for the -O0 -O1 -O2 -O3 compiler, -O0 indicate that the -O0 is not optimized, -O1 is the default value, the -O3 optimization level is only the compiler, when compiling, generate debugging information . -gstabs This option claims to debug information in the Stabs format, but does not include GDB debugging information. You can use debugging information. -Static This option will ban the use of dynamic libraries, so compiled things, it is generally large, you don't need any dynamic connection library, you can run. -Share This option will try to use dynamic libraries Therefore, the generated file is relatively small, but the system needs the system by dynamic library. -Traditional tries to support the compiler to support traditional C language features [Reference information] -Linux / UNIX Advanced Programming Zhongke Hongqi Software Technology Co., Ltd. Published. Tsinghua University Press Publishing -Gcc man Page [Changelog] -2002-08-10 Ver 0.1 Releases the original document-2002-08-11 Ver 0.11 Modified Document format-2002-08-12 Ver 0.12 Add to static library, dynamic library parameters -2002 -08-16 Ver 0.16 Increased 4 stages of GCC compilation to run GCC / EGCS *********** Run GCC / EGCS **************** ******* GCC is a GNU's C and C compiler. In fact, GCC can compile three languages: C, C and Object C (an object-oriented extension of C language). The C and C source programs can be compiled and connected with the GCC command. If you have two or a few C source files, you can easily compile, connect, and generate executables using GCC. For example, suppose you have two source files main.c and factorial.c two source files, and now you have to build a program that generates a calculating order.

Code: ----------------------- List Factorial.c --------------------- - int factorial (int N) {IF (n <= 1) Return 1; Else Return Factorial (N - 1) * n;} ------------------- ---- List main.c ----------------------- #include #include int fact (int N) ); Int main (int Argc, char ** argv) {int N; if (argc <2) {Printf ("USAGE:% S n / n", argv [0]); return -1;} else {n = ATOI (Argv [1]); Printf ("Factorial OF% D IS% D. / N", N, Factorial (N));} return 0;} ------------- ---------- Use the following command to build executable, and execute the program: $ gcc -o factorial main.c factorial.c $ .factorial 5 Factorial of 5 is 120. GCC can be Used to compile C processes and C programs. In general, the C compiler is determined by the suffix name of the source file or a C program. In Linux, the suffix of the C source file is called .c, and the suffix of the C source file is .c or .cpp. However, the GCC command can only compile C source files, and the library that cannot be automatically used automatically and C programs. Therefore, the G command is usually used to complete the compilation and connection of the C program, which automatically calls GCC implementation compilation. Suppose we have a C source file (hello.c): #include void main (void) {cout << "Hello, World!" << endl;}, you can call G command compile, connection and Generate executable: $ g -o hello hello.c $ ./HELLO HELLO, World! *********************** GCC / EGCS's main options * ******** The common option options for gcc commands Explain -ansi only support ANSI standard C syntax. This option will prohibit certain features of GNU C, such as ASM or TYPEOF keywords. -C only compiles and generates a target file. -Dmacro defines the MacRo macro with a string "1". -Dmacro = DEFN defines the MacRo macro in the string "DEFN". -E runs only the C pre-encoder. -G generate debugging information. The GNU debugger can take advantage of this information. -Idirectory Specifies the additional header search path Directory. -LDirectory Specifies the additional library search path Directory. -Llibrary is searched for the specified library library. -M486 performs code optimization for 486. -O file generates a specified output file. When generating an executable file.

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

New Post(0)