关于gcc编译时的各种参数,gcc手册里面可以找到详细解释。
1.而关于gcc手册,网上就有很多:
GCC online documentation – GNU Project – Free Software Foundation (FSF)
->
比如4.9.2的:
Using the GNU Compiler Collection (GCC)
->
其中关于各种参数,这里有个概述:
Option Summary – Using the GNU Compiler Collection (GCC)
比如常见的:
include文件夹的:-I就属于:
Directory Options See Options for Directory Search. -Bprefix -Idir-iplugindir=dir -iquotedir -Ldir -specs=file -I- --sysroot=dir --no-sysroot-suffix
link库的:-l就属于:
Linker Options See Options for Linking. object-file-name -llibrary -nostartfiles -nodefaultlibs -nostdlib -pie -rdynamic -s -static -static-libgcc -static-libstdc++ -static-libasan -static-libtsan -static-liblsan -static-libubsan -shared -shared-libgcc -symbolic -T script -Wl,option -Xlinker option -u symbol
2.另外这里也有手册解释:
Using the GNU Compiler Collection (GCC)
->
Invoking GCC – Using the GNU Compiler Collection (GCC)
常见的gcc参数,大概分类为:
- Option Summary: Brief list of all options, without explanations.
- Overall Options: Controlling the kind of output: an executable, object files, assembler files, or preprocessed source.
- Invoking G++: Compiling C++ programs.
- C Dialect Options: Controlling the variant of C language compiled.
- C++ Dialect Options: Variations on C++.
- Objective-C and Objective-C++ Dialect Options: Variations on Objective-C and Objective-C++.
- Language Independent Options: Controlling how diagnostics should be formatted.
- Warning Options: How picky should the compiler be?
- Debugging Options: Symbol tables, measurements, and debugging dumps.
- Optimize Options: How much optimization?
- Preprocessor Options: Controlling header files and macro definitions. Also, getting dependency information for Make.
- Assembler Options: Passing options to the assembler.
- Link Options: Specifying libraries and so on.
- Directory Options: Where to find header files and libraries. Where to find the compiler executable files.
- Spec Files: How to pass switches to sub-processes.
- Target Options: Running a cross-compiler, or an old version of GCC.
- Submodel Options: Specifying minor hardware or convention variations, such as 68010 vs 68020.
- Code Gen Options: Specifying conventions for function calls, data layout and register usage.
- Environment Variables: Env vars that affect GCC.
- Precompiled Headers: Compiling a header once, and using it many times.
3.下面摘录一些常见的参数的解释:
Link Options – Using the GNU Compiler Collection (GCC)
“
-l
library-l
libraryIt makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.
The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.
The directories searched include several standard system directories plus any that you specify with -L.
Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.
-lobjc
”
4.
Directory Options – Using the GNU Compiler Collection (GCC)
“
-c
-S
-E
-I
dirIf a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option is ignored. The directory is still searched but as a system directory at its normal position in the system include chain. This is to ensure that GCC’s procedure to fix buggy system headers and the ordering for the include_next
directive are not inadvertently changed. If you really need to change the search order for system directories, use the -nostdinc and/or -isystem options.
-L
dir”
5.
Overall Options – Using the GNU Compiler Collection (GCC)
“
-c
By default, the object file name for a source file is made by replacing the suffix ‘.c’, ‘.i’, ‘.s’, etc., with ‘.o’.
Unrecognized input files, not requiring compilation or assembly, are ignored.
-o
fileIf -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.
-v
--version
--help
”
6.
Preprocessor Options – Using the GNU Compiler Collection (GCC)
“
-I
dir=
, then the =
will be replaced by the sysroot prefix; see –sysroot and -isysroot.-o
file-Wall
#if
expressions. Note that many of the preprocessor’s warnings are on by default and have no options to control them.”
转载请注明:在路上 » 【整理】gcc常见参数含义解释