1、GCC介绍
GCC:GNU Compiler Collection(GNU 编译器集合),它可以编译C、C++、JAV、Fortran、Pascal、Object-C等语言。
gcc是GCC中的GUN C Compiler(C 编译器)。
g++是GCC中的GUN C++ Compiler(C++编译器)。
2、GCC man手册
如下为gcc的man帮助手册的第2部分(第546~746行)。
546 files, or into one assembler input file; then each assembler input file produces an object file, and linking
547 combines all the object files (those newly compiled, and those specified as input) into an executable file.
548 For any given input file, the file name suffix determines what kind of compilation is done:
549 file.c
550 C source code that must be preprocessed.
551 file.i
552 C source code that should not be preprocessed.
553 file.ii
554 C++ source code that should not be preprocessed.
555 file.m
556 Objective-C source code. Note that you must link with the libobjc library to make an Objective-C program
557 work.
558 file.mi
559 Objective-C source code that should not be preprocessed.
560 file.mm
561 file.M
562 Objective-C++ source code. Note that you must link with the libobjc library to make an Objective-C++
563 program work. Note that .M refers to a literal capital M.
564 file.mii
565 Objective-C++ source code that should not be preprocessed.
566 file.h
567 C, C++, Objective-C or Objective-C++ header file to be turned into a precompiled header (default), or C,
568 C++ header file to be turned into an Ada spec (via the -fdump-ada-spec switch).
569 file.cc
570 file.cp
571 file.cxx
572 file.cpp
573 file.CPP
574 file.c++
575 file.C
576 C++ source code that must be preprocessed. Note that in .cxx, the last two letters must both be literally
577 x. Likewise, .C refers to a literal capital C.
578 file.mm
579 file.M
580 Objective-C++ source code that must be preprocessed.
581 file.mii
582 Objective-C++ source code that should not be preprocessed.
583 file.hh
584 file.H
585 file.hp
586 file.hxx
587 file.hpp
588 file.HPP
589 file.h++
590 file.tcc
591 C++ header file to be turned into a precompiled header or Ada spec.
592 file.f
593 file.for
594 file.ftn
595 Fixed form Fortran source code that should not be preprocessed.
596 file.F
597 file.FOR
598 file.fpp
599 file.FPP
600 file.FTN
601 Fixed form Fortran source code that must be preprocessed (with the traditional preprocessor).
602 file.f90
603 file.f95
604 file.f03
605 file.f08
606 Free form Fortran source code that should not be preprocessed.
607 file.F90
608 file.F95
609 file.F03
610 file.F08
611 Free form Fortran source code that must be preprocessed (with the traditional preprocessor).
612 file.go
613 Go source code.
614 file.brig
615 BRIG files (binary representation of HSAIL).
616 file.d
617 D source code.
618 file.di
619 D interface file.
620 file.dd
621 D documentation code (Ddoc).
622 file.ads
623 Ada source code file that contains a library unit declaration (a declaration of a package, subprogram, or
624 generic, or a generic instantiation), or a library unit renaming declaration (a package, generic, or
625 subprogram renaming declaration). Such files are also called specs.
626 file.adb
627 Ada source code file containing a library unit body (a subprogram or package body). Such files are also
628 called bodies.
629 file.s
630 Assembler code.
631 file.S
632 file.sx
633 Assembler code that must be preprocessed.
634 other
635 An object file to be fed straight into linking. Any file name with no recognized suffix is treated this
636 way.
637 You can specify the input language explicitly with the -x option:
638 -x language
639 Specify explicitly the language for the following input files (rather than letting the compiler choose a
640 default based on the file name suffix). This option applies to all following input files until the next -x
641 option. Possible values for language are:
642 c c-header cpp-output
643 c++ c++-header c++-system-header c++-user-header c++-cpp-output
644 objective-c objective-c-header objective-c-cpp-output
645 objective-c++ objective-c++-header objective-c++-cpp-output
646 assembler assembler-with-cpp
647 ada
648 d
649 f77 f77-cpp-input f95 f95-cpp-input
650 go
651 brig
652 -x none
653 Turn off any specification of a language, so that subsequent files are handled according to their file name
654 suffixes (as they are if -x has not been used at all).
655 If you only want some of the stages of compilation, you can use -x (or filename suffixes) to tell gcc where to
656 start, and one of the options -c, -S, or -E to say where gcc is to stop. Note that some combinations (for
657 example, -x cpp-output -E) instruct gcc to do nothing at all.
658 -c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate
659 output is in the form of an object file for each source file.
660 By default, the object file name for a source file is made by replacing the suffix .c, .i, .s, etc., with
661 .o.
662 Unrecognized input files, not requiring compilation or assembly, are ignored.
663 -S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler
664 code file for each non-assembler input file specified.
665 By default, the assembler file name for a source file is made by replacing the suffix .c, .i, etc., with
666 .s.
667 Input files that don't require compilation are ignored.
668 -E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of
669 preprocessed source code, which is sent to the standard output.
670 Input files that don't require preprocessing are ignored.
671 -o file
672 Place the primary output in file file. This applies to whatever sort of output is being produced, whether
673 it be an executable file, an object file, an assembler file or preprocessed C code.
674 If -o is not specified, the default is to put an executable file in a.out, the object file for
675 source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch,
676 and all preprocessed C source on standard output.
677 Though -o names only the primary output, it also affects the naming of auxiliary and dump outputs. See the
678 examples below. Unless overridden, both auxiliary outputs and dump outputs are placed in the same
679 directory as the primary output. In auxiliary outputs, the suffix of the input file is replaced with that
680 of the auxiliary output file type; in dump outputs, the suffix of the dump file is appended to the input
681 file suffix. In compilation commands, the base name of both auxiliary and dump outputs is that of the
682 primary output; in compile and link commands, the primary output name, minus the executable suffix, is
683 combined with the input file name. If both share the same base name, disregarding the suffix, the result
684 of the combination is that base name, otherwise, they are concatenated, separated by a dash.
685 gcc -c foo.c ...
686 will use foo.o as the primary output, and place aux outputs and dumps next to it, e.g., aux file foo.dwo
687 for -gsplit-dwarf, and dump file foo.c.???r.final for -fdump-rtl-final.
688 If a non-linker output file is explicitly specified, aux and dump files by default take the same base name:
689 gcc -c foo.c -o dir/foobar.o ...
690 will name aux outputs dir/foobar.* and dump outputs dir/foobar.c.*.
691 A linker output will instead prefix aux and dump outputs:
692 gcc foo.c bar.c -o dir/foobar ...
693 will generally name aux outputs dir/foobar-foo.* and dir/foobar-bar.*, and dump outputs dir/foobar-foo.c.*
694 and dir/foobar-bar.c.*.
695 The one exception to the above is when the executable shares the base name with the single input:
696 gcc foo.c -o dir/foo ...
697 in which case aux outputs are named dir/foo.* and dump outputs named dir/foo.c.*.
698 The location and the names of auxiliary and dump outputs can be adjusted by the options -dumpbase,
699 -dumpbase-ext, -dumpdir, -save-temps=cwd, and -save-temps=obj.
700 -dumpbase dumpbase
701 This option sets the base name for auxiliary and dump output files. It does not affect the name of the
702 primary output file. Intermediate outputs, when preserved, are not regarded as primary outputs, but as
703 auxiliary outputs:
704 gcc -save-temps -S foo.c
705 saves the (no longer) temporary preprocessed file in foo.i, and then compiles to the (implied) output file
706 foo.s, whereas:
707 gcc -save-temps -dumpbase save-foo -c foo.c
708 preprocesses to in save-foo.i, compiles to save-foo.s (now an intermediate, thus auxiliary output), and
709 then assembles to the (implied) output file foo.o.
710 Absent this option, dump and aux files take their names from the input file, or from the (non-linker)
711 output file, if one is explicitly specified: dump output files (e.g. those requested by -fdump-* options)
712 with the input name suffix, and aux output files (those requested by other non-dump options, e.g.
713 "-save-temps", "-gsplit-dwarf", "-fcallgraph-info") without it.
714 Similar suffix differentiation of dump and aux outputs can be attained for explicitly-given -dumpbase
715 basename.suf by also specifying -dumpbase-ext .suf.
716 If dumpbase is explicitly specified with any directory component, any dumppfx specification (e.g. -dumpdir
717 or -save-temps=*) is ignored, and instead of appending to it, dumpbase fully overrides it:
718 gcc foo.c -c -o dir/foo.o -dumpbase alt/foo \
719 -dumpdir pfx- -save-temps=cwd ...
720 creates auxiliary and dump outputs named alt/foo.*, disregarding dir/ in -o, the ./ prefix implied by
721 -save-temps=cwd, and pfx- in -dumpdir.
722 When -dumpbase is specified in a command that compiles multiple inputs, or that compiles and then links, it
723 may be combined with dumppfx, as specified under -dumpdir. Then, each input file is compiled using the
724 combined dumppfx, and default values for dumpbase and auxdropsuf are computed for each input file:
725 gcc foo.c bar.c -c -dumpbase main ...
726 creates foo.o and bar.o as primary outputs, and avoids overwriting the auxiliary and dump outputs by using
727 the dumpbase as a prefix, creating auxiliary and dump outputs named main-foo.* and main-bar.*.
728 An empty string specified as dumpbase avoids the influence of the output basename in the naming of
729 auxiliary and dump outputs during compilation, computing default values :
730 gcc -c foo.c -o dir/foobar.o -dumpbase " ...
731 will name aux outputs dir/foo.* and dump outputs dir/foo.c.*. Note how their basenames are taken from the
732 input name, but the directory still defaults to that of the output.
733 The empty-string dumpbase does not prevent the use of the output basename for outputs during linking:
734 gcc foo.c bar.c -o dir/foobar -dumpbase " -flto ...
735 The compilation of the source files will name auxiliary outputs dir/foo.* and dir/bar.*, and dump outputs
736 dir/foo.c.* and dir/bar.c.*. LTO recompilation during linking will use dir/foobar. as the prefix for dumps
737 and auxiliary files.
738 -dumpbase-ext auxdropsuf
739 When forming the name of an auxiliary (but not a dump) output file, drop trailing auxdropsuf from dumpbase
740 before appending any suffixes. If not specified, this option defaults to the suffix of a default dumpbase,
741 i.e., the suffix of the input file when -dumpbase is not present in the command line, or dumpbase is
742 combined with dumppfx.
743 gcc foo.c -c -o dir/foo.o -dumpbase x-foo.c -dumpbase-ext .c ...
744 creates dir/foo.o as the main output, and generates auxiliary outputs in dir/x-foo.*, taking the location
745 of the primary output, and dropping the .c suffix from the dumpbase. Dump outputs retain the suffix:
746 dir/x-foo.c.*.