最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】gcc常见参数含义解释

gcc crifan 4748浏览 0评论

关于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参数,大概分类为:

 

3.下面摘录一些常见的参数的解释:

Link Options – Using the GNU Compiler Collection (GCC)

-llibrary

-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

It 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
You need this special case of the -l option in order to link an Objective-C or Objective-C++ program.

 

4.

Directory Options – Using the GNU Compiler Collection (GCC)

-c
-S
-E
If any of these options is used, then the linker is not run, and object file names should not be used as arguments. See Overall Options.
-Idir
Add the directory dir to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. However, you should not use this option to add directories that contain vendor-supplied system header files (use -isystem for that). If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come after.

If 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.

-Ldir
Add directory dir to the list of directories to be searched for -l.

 

5.

Overall Options – Using the GNU Compiler Collection (GCC)

-c
Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.

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 file
Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

If -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
Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper.
--version
Display the version number and copyrights of the invoked GCC.
--help
Print (on the standard output) a description of the command-line options understood by gcc. If the -v option is also specified then –help is also passed on to the various processes invoked by gcc, so that they can display the command-line options they accept. If the -Wextra option has also been specified (prior to the –help option), then command-line options that have no documentation associated with them are also displayed.

 

6.

Preprocessor Options – Using the GNU Compiler Collection (GCC)

-I dir

Add the directory dir to the list of directories to be searched for header files. Directories named by -I are searched before the standard system include directories. If the directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated . If dir begins with =, then the = will be replaced by the sysroot prefix; see –sysroot and -isysroot.

-o file
Write output to file. This is the same as specifying file as the second non-option argument to cpp. gcc has a different interpretation of a second non-option argument, so you must use -o to specify the output file.

-Wall
Turns on all optional warnings which are desirable for normal code. At present this is -Wcomment, -Wtrigraphs, -Wmultichar and a warning about integer promotion causing a change of sign in #if expressions. Note that many of the preprocessor’s warnings are on by default and have no options to control them.

转载请注明:在路上 » 【整理】gcc常见参数含义解释

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.206 seconds, using 22.12MB memory