One .GCC history
GCC is the earliest compiler for Richard Stallman in more than ten years ago. It means that GNU C Compiler, and later develops ADA, C , Java, Objective C, Pascal, Cobol, and support logical programming Mercury language. Later, the original name of the English became: GNU Compiler Ollection ([1]). In addition, GCC provides comprehensive support for various hardware platforms.
In general, GCC compilation features include GCC (C "compilers), G (C compiler), in the compilation process, has four steps in work.
1. Preprocessing, generating I files, C file compiles to .i file, C file compile to .II file, all of them are the source program's pre-processing result file. Take the easiest Hello World program:
******************************** // Test.c # incrude "stdio.h" #define Max 9
INT main () {Int a; a = max; Printf ("Hello Worldn");} ************************************** ****
With CPP Test.c Test.i, you can get the pre-processing file Test.i, by viewing the file, we can see that the include files we introduced have been introduced, and the part defined by the define has been fully brought.
2. The pre-processing file is converted into assembly language and generates .s file. This step uses EGCS to complete (this precompiler is not seen in the MINGW standard package, so the test is not successful, will continue to test)
3. Compilation is changed to the target file, generates .o files, using AS to complete.
4. Connect the target file, generate an executable, complete with LD. (Follow-up to continue studying the LD compilation process.)
Two .GCC parameter auspicious solution
-x Language FileName Set the language used by the file, which is invalid, and multiple compilation files after the GCC are valid. This if there is a problem with the .C and .CPP files, solve this problem with the next parameter -X None filename, introduced below. Since the processing method of .c and .cpp files are different during the pretreatment process. The parameters that can be used are: 'c', 'Objective-C', 'c-header', 'c ', 'cpp-output', 'assemer', 'assemer-with-cpp'. When there is Such a file written with the Test.TMP with the C language uses GCC -XC Test.TMP to compile Test.TMP with the GCC -XC Test.tmp when compiled with GCC.
-x none filename turns off the previous option, which is to automatically identify file types based on the file name suffix. Compile: gcc-x c test.tmp-x none test2.c This is free to choose compilation
-c only activates pretreatment, compile and assembly, which is to make the program into an OBJ file. If gcc -c test.c generates Test.o files, of course, this is only a target file, and you need to connect all .o files to generate executables through the LD connector.
-S only activates pre-processing and compile, compiles files to assembly code. It is equivalent to doing an EGCS operation in the source program to generate .s file. You can view the result of the generated assembly file. This is very effective for programmers who study assembly language.
-E only activates pre-processing, which will prepare files, will be converted to all introduced include files and define definitions, the first step of the GCC compiled, that is, using the CPP command The language file is preprocessing. But this step does not generate a result file, and if you need to generate a result file saving, you need to use the output redirection in the system. -o custom target name, the result of the GCC filename under UNIX and Linux platforms is a file named A.out, and the GCC compile results in MINGW will be a.exe. If we use gcc -o hello.exe test.c, a Hello.exe executable will be generated. This does not necessarily only be limited to the generation of the last step executable program. If the -s generated by the -s-S-S-S-S-S-S-S, such as gcc -o hello.asm -s test.c like this Hello.ASM That is the result of Test.c after pretreatment and compiling.
-pipe uses a pipe instead of the temporary file in the compilation, because the entire process of compilation has several different steps, each step is the output of the previous step, which involves the problem of data transmission, where there is no In the case of a PIPE parameter, it is passed in the form of a temporary file. When this is, the pipe is used to pass the intermediate data. Of course, in some systems, the assembly cannot read pipe data so that this parameter cannot work.
-ansi off the characteristics of GNU C and ANSI C, activate ANSI C's exclusive characteristics, in which case the processor will define a macro of __strict_ansi__, and will pay attention to this macro in some headers. To avoid the introduction of certain functions. This item can be referred to the difference between ANSI C and GNU C.
-fno-asm This option is part of the ANSI option function, disables the use of ASM, Inline, TypeOf as a keyword.
-fno-strict-prototype This option is only a role in G . This parameter allows the compiler to consider all of the unparalleled functions as a function without the number of explicit parameters, not without parameters. For GCC, there is no type of function without the parameters, and there is no explicitly described type.
-fthis-is-variable This parameter is only valid for the C program, allowing this to use general variables, allowing this assignment to this.
-fcond-mismatch allows the second and third parameter types of the conditional expression to do not match. The value of the expression is a VOID type.
-funsigned-char-fno-signed-char-fsigned-char-fno-unsigned-char-a set of char in compile time, which determines the char or Signed Char, respectively.
-include filename Add to the header of the header to make the program to use #include in the program, so you can compile when compiling: GCC Test.c
-Include ./include/test.h, coupled.
-imacros filename expands the macros in FileName into the GCC input file, the macro defined itself does not appear in the input file. When compiling a file Test.c, it has been discarded after generating the target file when it is not used by this parameter, and after using this parameter, these macro will be Retain compilation for the file after it.
-Dmacro is equivalent to #define macro, the content of the macro is a string '1'. If you use gcc -o test.exe test.c -ddebug as in compilation, it is equivalent to defining a debug macro in Test.c, and the value is string '1'. It can be tested as follows: ********************** // Test.c # incrude "stdio. {Printf ("Hello WorldN"); #ifdef debug printf ("hellon"); #ENDIF} ****************************** ************
If you compile with gcc -o test.exe test.c, just compiled by hello world, if you compile with gcc -o test.exe test.c -ddebug, the results are: Hello Worldhello
Therefore, it can be equivalent to the DEBUG macro in Test.c in the next compilation method.
-Dmacro = Define The effect is the same, but the value of the macro is define.
-Umacro is equivalent to a macro defined in the program. Undefine. Ie: #undef macro
-undef canceled the definition of any non-standard friends
-IDIR When you #include, you will find a header file in the location specified by this parameter. If you are not found, you can find a file to the default directory.
-I- Cancel-Idir's role, indicating that the program later will not find the header file in the directory specified in -idir.
-idirafter Dir looks for failure in the -i directory, then lookup header files in this directory, such parameters are more helpful for setting the priority problem for setting header files.
-iprefix prefix-irlprefix DIR These two parameters are used together. When the -i directory is looking for failure, check the header files to the prefix DIR.
-nostdinc compilers are no longer the system default header file directory to find head files. This will accurately determine the source of the header file, should be used with caution, which is easy to cause compilation without understanding the compiler.
-nostdinc C does not look back in G standard path, but continue to find in other paths. Use it when you create LiB.
-C In order to effectively analyze the program, the comment information is not deleted when preprocessing, is used with -e, and has the process of using the analyst.
-M generates information about the association of files, so you can know which project files are associated with the header files it dependent.
-Mm is the same, but ignores the dependencies caused by #include
-Md is equivalent to -m, but the output is imported into the .d file, such as gcc-md test.c, the just-output dependency is stored in the Test.d file.
-Mmd is the same as -mm, but output to the .d file, such as gcc -md test.c, the just-output dependency is stored in the Test.d file. Ignore the relationship between #include
-Wa, Option This parameter passes the Option to the assembler. If there is a comma in the option, the Option is divided into multiple items, and passed to the assembler.
-Wl, Option This parameter passes the Option to the connection program. If there is a comma in the Option, the OPTION is divided into multiple items, transmitted to the connection program.
-llibrary is used to develop the library used when compilation, such as gcc -lgtk tset.c, using the GTK library to compile, but it is necessary to note that the GCC library is generally named library files in libName.a, in -l When the parameter is added to the library file, directly use -lname to introduce, and the front LIB is saved. This needs attention. -Ldir compiles the path to set the library file, otherwise, the compiler is only looking for the library in the standard library path.
-00-01-02-03 Compiler Optimization Option, -00 indicates that there is no optimization, -01 is the default value, and -03 is the highest.
-g When compiling, create debugging information
-gstabs claims to debug information in Stabs format, but does not include the debugging information of GDB.
-gstabs claims to debug information in Stabs format, including GDB debugging information.
-ggdb This parameter will output GDB debug information
-static This parameter will disable the use of dynamic libraries, so that the program can only connect the static library.
-Share This parameter will make the program to use dynamic libraries as possible
-traditional tries to allow the compiler to support the characteristics of traditional C language.
Summary
The parameters of GCC are far more than these, but more than the above parameters can be more skilled in most compilation of GCC, more parameter introduction, can refer to GCC's Manual, now have translated The Chinese manual, the address is listed below, and interesting friends can be referred to.
[1] http://www-900.ibm.com/developerWorks/cn/linux/L-GCC/PART1/ GNU Compiler Family GCC internal probe Zhao Wei zhaoway@public1.ptt.js.cn)
[2] http://www.21ic.com/news/n5203c79.aspx gcc Chinese manual Xu Ming