亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

gcc

系統(tǒng) 1910 0

gcc使用的方法 -- 作者: www.linuxfans.org mozilla
1。gcc包含的c/c++編譯器
gcc,cc,c++,g++,gcc和cc是一樣的,c++和g++是一樣的,一般c程序就用gcc編譯,c++程序就用g++編譯

2。gcc的基本用法
gcc test.c這樣將編譯出一個(gè)名為a.out的程序
gcc test.c -o test這樣將編譯出一個(gè)名為test的程序,-o參數(shù)用來(lái)指定生成程序的名字

3。為什么會(huì)出現(xiàn)undefined reference to 'xxxxx'錯(cuò)誤?
首先這是鏈接錯(cuò)誤,不是編譯錯(cuò)誤,也就是說(shuō)如果只有這個(gè)錯(cuò)誤,說(shuō)明你的程序源碼本身沒(méi)有問(wèn)題,是你用編譯器編譯時(shí)參數(shù)用得不對(duì),你沒(méi)有指定鏈接程序要用到得庫(kù),比如你的程序里用到了一些數(shù)學(xué)函數(shù),那么你就要在編譯參數(shù)里指定程序要鏈接數(shù)學(xué)庫(kù),方法是在編譯命令行里加入-lm。

4。-l參數(shù)和-L參數(shù)
-l參數(shù)就是用來(lái)指定程序要鏈接的庫(kù),-l參數(shù)緊接著就是庫(kù)名,那么庫(kù)名跟真正的庫(kù)文件名有什么關(guān)系呢?
就拿數(shù)學(xué)庫(kù)來(lái)說(shuō),他的庫(kù)名是m,他的庫(kù)文件名是libm.so,很容易看出,把庫(kù)文件名的頭lib和尾.so去掉就是庫(kù)名了。

好了現(xiàn)在我們知道怎么得到庫(kù)名了,比如我們自已要用到一個(gè)第三方提供的庫(kù)名字叫l(wèi)ibtest.so,那么我們只要把libtest.so拷貝到/usr/lib里,編譯時(shí)加上-ltest參數(shù),我們就能用上libtest.so庫(kù)了(當(dāng)然要用libtest.so庫(kù)里的函數(shù),我們還需要與libtest.so配套的頭文件)。

放在/lib和/usr/lib和/usr/local/lib里的庫(kù)直接用-l參數(shù)就能鏈接了,但如果庫(kù)文件沒(méi)放在這三個(gè)目錄里,而是放在其他目錄里,這時(shí)我們只用-l參數(shù)的話,鏈接還是會(huì)出錯(cuò),出錯(cuò)信息大概是:"/usr/bin/ld: cannot find -lxxx",也就是鏈接程序ld在那3個(gè)目錄里找不到libxxx.so,這時(shí)另外一個(gè)參數(shù)-L就派上用場(chǎng)了,比如常用的X11的庫(kù),它放在/usr/X11R6/lib目錄下,我們編譯時(shí)就要用-L/usr/X11R6/lib -lX11參數(shù),-L參數(shù)跟著的是庫(kù)文件所在的目錄名。再比如我們把libtest.so放在/aaa/bbb/ccc目錄下,那鏈接參數(shù)就是-L/aaa/bbb/ccc -ltest

另外,大部分libxxxx.so只是一個(gè)鏈接,以RH9為例,比如libm.so它鏈接到/lib/libm.so.x,/lib/libm.so.6又鏈接到/lib/libm-2.3.2.so,如果沒(méi)有這樣的鏈接,還是會(huì)出錯(cuò),因?yàn)閘d只會(huì)找libxxxx.so,所以如果你要用到xxxx庫(kù),而只有l(wèi)ibxxxx.so.x或者libxxxx-x.x.x.so,做一個(gè)鏈接就可以了ln -s libxxxx-x.x.x.so libxxxx.so

手工來(lái)寫鏈接參數(shù)總是很麻煩的,還好很多庫(kù)開(kāi)發(fā)包提供了生成鏈接參數(shù)的程序,名字一般叫xxxx-config,一般放在/usr/bin目錄下,比如gtk1.2的鏈接參數(shù)生成程序是gtk-config,執(zhí)行g(shù)tk-config --libs就能得到以下輸出"-L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXi -lXext -lX11 -lm",這就是編譯一個(gè)gtk1.2程序所需的gtk鏈接參數(shù),xxx-config除了--libs參數(shù)外還有一個(gè)參數(shù)是--cflags用來(lái)生成頭文
件包含目錄的,也就是-I參數(shù),在下面我們將會(huì)講到。你可以試試執(zhí)行g(shù)tk-config --libs --cflags,看看輸出結(jié)果。
現(xiàn)在的問(wèn)題就是怎樣用這些輸出結(jié)果了,最苯的方法就是復(fù)制粘貼或者照抄,聰明的辦法是在編譯命令行里加入這個(gè)`xxxx-config --libs --cflags`,比如編譯一個(gè)gtk程序:gcc gtktest.c `gtk-config --libs --cflags`這樣就差
不多了。注意`不是單引號(hào),而是1鍵左邊那個(gè)鍵。

除了xxx-config以外,現(xiàn)在新的開(kāi)發(fā)包一般都用pkg-config來(lái)生成鏈接參數(shù),使用方法跟xxx-config類似,但xxx-config是針對(duì)特定的開(kāi)發(fā)包,但pkg-config包含很多開(kāi)發(fā)包的鏈接參數(shù)的生成,用pkg-config --list-all命令可以列出所支持的所有開(kāi)發(fā)包,pkg-config的用法就是pkg-config pagName --libs --cflags,其中pagName是包名,是pkg-config--list-all里列出名單中的一個(gè),比如gtk1.2的名字就是gtk+,pkg-config gtk+ --libs --cflags的作用跟gtk-config --libs --cflags是一樣的。比如:gcc gtktest.c `pkg-config gtk+ --libs --cflags`。

5。-include和-I參數(shù)
-include用來(lái)包含頭文件,但一般情況下包含頭文件都在源碼里用#include xxxxxx實(shí)現(xiàn),-include參數(shù)很少用。-I參數(shù)是用來(lái)指定頭文件目錄,/usr/include目錄一般是不用指定的,gcc知道去那里找,但是如果頭文件不在/usr/include里我們就要用-I參數(shù)指定了,比如頭文件放在/myinclude目錄里,那編譯命令行就要加上-I/myinclude參數(shù)了,如果不加你會(huì)得到一個(gè)"xxxx.h: No such file or directory"的錯(cuò)誤。-I參數(shù)可以用相對(duì)路徑,比如頭文件在當(dāng)前目錄,可以用-I.來(lái)指定。上面我們提到的--cflags參數(shù)就是用來(lái)生成-I參數(shù)的。

6。-O參數(shù)
這是一個(gè)程序優(yōu)化參數(shù),一般用-O2就是,用來(lái)優(yōu)化程序用的,比如gcc test.c -O2,優(yōu)化得到的程序比沒(méi)優(yōu)化的要小,執(zhí)行速度可能也有所提高(我沒(méi)有測(cè)試過(guò))。

7。-shared參數(shù)
編譯動(dòng)態(tài)庫(kù)時(shí)要用到,比如gcc -shared test.c -o libtest.so

8。幾個(gè)相關(guān)的環(huán)境變量
PKG_CONFIG_PATH:用來(lái)指定pkg-config用到的pc文件的路徑,默認(rèn)是/usr/lib/pkgconfig,pc文件是文本文件,擴(kuò)展名是.pc,里面定義開(kāi)發(fā)包的安裝路徑,Libs參數(shù)和Cflags參數(shù)等等。
CC:用來(lái)指定c編譯器。
CXX:用來(lái)指定cxx編譯器。
LIBS:跟上面的--libs作用差不多。
CFLAGS:跟上面的--cflags作用差不多。
CC,CXX,LIBS,CFLAGS手動(dòng)編譯時(shí)一般用不上,在做configure時(shí)有時(shí)用到,一般情況下不用管。
環(huán)境變量設(shè)定方法:export ENV_NAME=xxxxxxxxxxxxxxxxx

9。關(guān)于交叉編譯
交叉編譯通俗地講就是在一種平臺(tái)上編譯出能運(yùn)行在體系結(jié)構(gòu)不同的另一種平臺(tái)上,比如在我們地PC平臺(tái)(X86 CPU)上編譯出能運(yùn)行在sparc CPU平臺(tái)上的程序,編譯得到的程序在X86 CPU平臺(tái)上是不能運(yùn)行的,必須放到sparc CPU平臺(tái)上才能運(yùn)行。
當(dāng)然兩個(gè)平臺(tái)用的都是linux。

這種方法在異平臺(tái)移植和嵌入式開(kāi)發(fā)時(shí)用得非常普遍。

相對(duì)與交叉編譯,我們平常做的編譯就叫本地編譯,也就是在當(dāng)前平臺(tái)編譯,編譯得到的程序也是在本地執(zhí)行。

用來(lái)編譯這種程序的編譯器就叫交叉編譯器,相對(duì)來(lái)說(shuō),用來(lái)做本地編譯的就叫本地編譯器,一般用的都是gcc,但這種gcc跟本地的gcc編譯器是不一樣的,需要在編譯gcc時(shí)用特定的configure參數(shù)才能得到支持交叉編譯的gcc。

為了不跟本地編譯器混淆,交叉編譯器的名字一般都有前綴,比如sparc-xxxx-linux-gnu-gcc,sparc-xxxx-linux-gnu-g++ 等等

10。交叉編譯器的使用方法
使用方法跟本地的gcc差不多,但有一點(diǎn)特殊的是:必須用-L和-I參數(shù)指定編譯器用sparc系統(tǒng)的庫(kù)和頭文件,不能用本地(X86)
的庫(kù)(頭文件有時(shí)可以用本地的)。
例子:
sparc-xxxx-linux-gnu-gcc test.c -L/path/to/sparcLib -I/path/to/sparcInclude

- 作者: michaelbob 2005年03月20日, 星期日 14:08  回復(fù)(0) |  引用(0) 加入博采

[轉(zhuǎn)貼] GCC 使用指南
:[轉(zhuǎn)貼] GCC 使用指南
使用語(yǔ)法:


option | filename ]...

其中 option 為 gcc 使用時(shí)的選項(xiàng)(后面會(huì)再詳述),
   而 filename 為欲以 gcc 處理的文件

說(shuō)明:
這 C 與 C++ 的 compiler 已將產(chǎn)生新程序的相關(guān)程序整合起來(lái)。產(chǎn) 生一個(gè)新的程序需要經(jīng)過(guò)四個(gè)階段:預(yù)處理、編譯、匯編、連結(jié),而這兩 個(gè)編譯器都能將輸入的文件做不同階段的處理。雖然原始程序的擴(kuò)展名可 用來(lái)分辨編寫原始程序碼所用的語(yǔ)言,但不同的compiler,其預(yù)設(shè)的處理 程序卻各不相同:

gcc  預(yù)設(shè)經(jīng)由預(yù)處理過(guò)(擴(kuò)展名為.i)的文件為 C 語(yǔ)言,并於程式
      連結(jié)階段以 C 的連結(jié)方式處理。

g++  預(yù)設(shè)經(jīng)由預(yù)處理過(guò)(擴(kuò)展名為.i)的文件為 C++ 語(yǔ)言,并於程序連結(jié)階段以 C++ 的連結(jié)方式處理。

原始程序碼的擴(kuò)展名指出所用編寫程序所用的語(yǔ)言,以及相對(duì)應(yīng)的處理方法:

   .c  C 原始程序         ; 預(yù)處理、編譯、匯編
   .C  C++ 原始程序        ; 預(yù)處理、編譯、匯編
   .cc C++ 原始程序        ; 預(yù)處理、編譯、匯編
   .cxx C++ 原始程序        ; 預(yù)處理、編譯、匯編
   .m  Objective-C 原始程序    ; 預(yù)處理、編譯、匯編
   .i  已經(jīng)過(guò)預(yù)處理之 C 原始程序  ; 編譯、匯編
   .ii 已經(jīng)過(guò)預(yù)處理之 C++ 原始程序 ; 編譯、匯編
   .s  組合語(yǔ)言原始程序      ; 匯編
   .S  組合語(yǔ)言原始程序      ; 預(yù)處理、匯編
   .h  預(yù)處理文件(標(biāo)頭文件)    ; (不常出現(xiàn)在指令行)

其他擴(kuò)展名的文件是由連結(jié)程序來(lái)處理,通常有:
   .o  Object file
   .a  Archive file

除非編譯過(guò)程出現(xiàn)錯(cuò)誤,否則 "連結(jié)" 一定是產(chǎn)生一個(gè)新程序的最
   後階段。然而你也可以以 -c、-s 或 -E 等選項(xiàng),將整個(gè)過(guò)程自四
   個(gè)階段中的其中一個(gè)停止。在連結(jié)階段,所有與原始碼相對(duì)應(yīng)的
   .o 文件、程序庫(kù)、和其他無(wú)法自文件名辨明屬性的文件(包括不以 .o
   為擴(kuò)展名的 object file 以及擴(kuò)展名為 .a 的 archive file)都會(huì)
   交由連結(jié)程序來(lái)處理(在指令行將那些文件當(dāng)作連結(jié)程序的參數(shù)傳給
   連結(jié)程序)。

選項(xiàng):

   不同的選項(xiàng)必須分開(kāi)來(lái)下:例如 `-dr' 這個(gè)選項(xiàng)就與 `-d -r' 大
   不相同。
   絕大部份的 `-f' 及 `-W' 選項(xiàng)都有正反兩種形式:-fname 及
   -fno-name (或 -Wname 及 -Wno-name)。以下只列出非預(yù)設(shè)的那個(gè)
   形式。
   以下是所有選項(xiàng)的摘要。以形式來(lái)分類。選項(xiàng)的意義將另辟小節(jié)說(shuō)
   明。

   一般性(概略、常用的)選項(xiàng)
       -c -S -E -o file -pipe -v -x language

   程序語(yǔ)言選項(xiàng)
       -ansi -fall-virtual -fcond-mismatch
       -fdollars-in-identifiers -fenum-int-equiv
       -fexternal-templates -fno-asm -fno-builtin
       -fno-strict-prototype -fsigned-bitfields
       -fsigned-char -fthis-is-variable
       -funsigned-bitfields -funsigned-char
       -fwritable-strings -traditional -traditional-cpp
       -trigraphs

   編譯時(shí)的警告選項(xiàng)
       -fsyntax-only -pedantic -pedantic-errors -w -W
       -Wall -Waggregate-return -Wcast-align -Wcast-qual
       -Wchar-subscript -Wcomment -Wconversion
       -Wenum-clash -Werror -Wformat -Wid-clash-len
       -Wimplicit -Winline -Wmissing-prototypes
       -Wmissing-declarations -Wnested-externs -Wno-import
       -Wparentheses -Wpointer-arith -Wredundant-decls
       -Wreturn-type -Wshadow -Wstrict-prototypes -Wswitch
       -Wtemplate-debugging -Wtraditional -Wtrigraphs
       -Wuninitialized -Wunused -Wwrite-strings

   除錯(cuò)選項(xiàng)
       -a -dletters -fpretend-float -g -glevel -gcoff
       -gxcoff -gxcoff+ -gdwarf -gdwarf+ -gstabs -gstabs+
       -ggdb -p -pg -save-temps -print-file-name=library
       -print-libgcc-file-name -print-prog-name=program

  最佳化選項(xiàng)
       -fcaller-saves -fcse-follow-jumps -fcse-skip-blocks
       -fdelayed-branch -felide-constructors
       -fexpensive-optimizations -ffast-math -ffloat-store
       -fforce-addr -fforce-mem -finline-functions
       -fkeep-inline-functions -fmemoize-lookups
       -fno-default-inline -fno-defer-pop
       -fno-function-cse -fno-inline -fno-peephole
       -fomit-frame-pointer -frerun-cse-after-loop
       -fschedule-insns -fschedule-insns2
       -fstrength-reduce -fthread-jumps -funroll-all-loops
       -funroll-loops -O -O2

   預(yù)處理選項(xiàng)
       -Aassertion -C -dD -dM -dN -Dmacro[=defn] -E -H
       -idirafter dir -include file -imacros file -iprefix
       file -iwithprefix dir -M -MD -MM -MMD -nostdinc -P
       -Umacro -undef

   匯編程序選項(xiàng)
       -Wa,option
   連結(jié)程序選項(xiàng)
       -llibrary -nostartfiles -nostdlib -static -shared
       -symbolic -Xlinker option -Wl,option -u symbol

  目錄選項(xiàng)
       -Bprefix -Idir -I- -Ldir

  Target Options
       -b machine -V version

  與機(jī)器(平臺(tái))相關(guān)的選項(xiàng)
       M680x0 Options
       -m68000 -m68020 -m68020-40 -m68030 -m68040 -m68881
       -mbitfield -mc68000 -mc68020 -mfpa -mnobitfield
       -mrtd -mshort -msoft-float

VAX Options
       -mg -mgnu -munix

SPARC Options
       -mepilogue -mfpu -mhard-float -mno-fpu
       -mno-epilogue -msoft-float -msparclite -mv8
       -msupersparc -mcypress

Convex Options
       -margcount -mc1 -mc2 -mnoargcount

AMD29K Options
       -m29000 -m29050 -mbw -mdw -mkernel-registers
       -mlarge -mnbw -mnodw -msmall -mstack-check
       -muser-registers

M88K Options
       -m88000 -m88100 -m88110 -mbig-pic
       -mcheck-zero-division -mhandle-large-shift
       -midentify-revision -mno-check-zero-division
       -mno-ocs-debug-info -mno-ocs-frame-position
       -mno-optimize-arg-area -mno-serialize-volatile
       -mno-underscores -mocs-debug-info
       -mocs-frame-position -moptimize-arg-area
       -mserialize-volatile -mshort-data-num -msvr3 -msvr4
       -mtrap-large-shift -muse-div-instruction
       -mversion-03.00 -mwarn-passed-structs

  RS6000 Options
       -mfp-in-toc -mno-fop-in-toc

RT Options
       -mcall-lib-mul -mfp-arg-in-fpregs -mfp-arg-in-gregs
       -mfull-fp-blocks -mhc-struct-return -min-line-mul
       -mminimum-fp-blocks -mnohc-struct-return

MIPS Options
       -mcpu=cpu type -mips2 -mips3 -mint64 -mlong64
       -mlonglong128 -mmips-as -mgas -mrnames -mno-rnames
       -mgpopt -mno-gpopt -mstats -mno-stats -mmemcpy
       -mno-memcpy -mno-mips-tfile -mmips-tfile
       -msoft-float -mhard-float -mabicalls -mno-abicalls
       -mhalf-pic -mno-half-pic -G num -nocpp

i386 Options
       -m486 -mno-486 -msoft-float -mno-fp-ret-in-387

HPPA Options
       -mpa-risc-1-0 -mpa-risc-1-1 -mkernel -mshared-libs
       -mno-shared-libs -mlong-calls -mdisable-fpregs
       -mdisable-indexing -mtrailing-colon

  i960 Options
       -mcpu-type -mnumerics -msoft-float
       -mleaf-procedures -mno-leaf-procedures -mtail-call
       -mno-tail-call -mcomplex-addr -mno-complex-addr
       -mcode-align -mno-code-align -mic-compat
       -mic2.0-compat -mic3.0-compat -masm-compat
       -mintel-asm -mstrict-align -mno-strict-align
       -mold-align -mno-old-align

  DEC Alpha Options
       -mfp-regs -mno-fp-regs -mno-soft-float -msoft-float

  System V Options
       -G -Qy -Qn -YP,paths -Ym,dir

  Code Generation Options
       -fcall-saved-reg -fcall-used-reg -ffixed-reg
       -finhibit-size-directive -fnonnull-objects
       -fno-common -fno-ident -fno-gnu-linker
       -fpcc-struct-return -fpic -fPIC
       -freg-struct-returno -fshared-data -fshort-enums
       -fshort-double -fvolatile -fvolatile-global
       -fverbose-asm

PRAGMAS
   Two `#pragma' directives are supported for GNU C++, to
   permit using the same header file for two purposes: as a
   definition of interfaces to a given object class, and as
   the full definition of the contents of that object class.

   #pragma interface
       (C++ only.) Use this directive in header files
       that define object classes, to save space in most
       of the object files that use those classes. Nor-
       mally, local copies of certain information (backup
       copies of inline member functions, debugging infor-
       mation, and the internal tables that implement vir-
       tual functions) must be kept in each object file
       that includes class definitions. You can use this
       pragma to avoid such duplication. When a header
       file containing `#pragma interface' is included in
       a compilation, this auxiliary information will not
       be generated (unless the main input source file it-
       self uses `#pragma implementation'). Instead, the
       object files will contain references to be resolved
       at link time.

   #pragma implementation

   #pragma implementation "objects.h"
       (C++ only.) Use this pragma in a main input file,
       when you want full output from included header
       files to be generated (and made globally visible).
       The included header file, in turn, should use
       `#pragma interface'. Backup copies of inline mem-
       ber functions, debugging information, and the in-
       ternal tables used to implement virtual functions
       are all generated in implementation files.

       If you use `#pragma implementation' with no argu-
       ment, it applies to an include file with the same
       basename as your source file; for example, in
       `allclass.cc', `#pragma implementation' by itself
       is equivalent  to  `#pragma  implementation
       "allclass.h"'. Use the string argument if you want
       a single implementation file to include code from
       multiple header files.

       There is no way to split up the contents of a sin-
       gle header file into multiple implementation files.

文件說(shuō)明
   file.c       C source file
   file.h       C header (preprocessor) file
   file.i       經(jīng)預(yù)處理過(guò)的 C source file
   file.C       C++ source file
   file.cc      C++ source file
   file.cxx     C++ source file
   file.m       Objective-C source file
   file.s       assembly language file
   file.o       object file
   a.out       link edited output
   TMPDIR/cc*     temporary files
   LIBDIR/cpp     preprocessor
   LIBDIR/cc1     compiler for C
   LIBDIR/cc1plus   compiler for C++
   LIBDIR/collect   linker front end needed on some machines
   LIBDIR/libgcc.a  GCC subroutine library
   /lib/crt[01n].o  start-up routine
   LIBDIR/ccrt0  additional start-up routine for C++
   /lib/libc.a    standard C library, 參閱 man page intro(3)
   /usr/include  standard directory for #include files
   LIBDIR/include   standard gcc directory for #include files
   LIBDIR/g++-include additional g++ directory for #include

   LIBDIR is usually /usr/local/lib/machine/version.
   TMPDIR comes from the environment variable TMPDIR (default
   /usr/tmp if available, else /tmp).

gcc最佳編譯參數(shù)

摘要   本文著重介紹在不同的硬件環(huán)境下給GCC指定哪些參數(shù)才可以得到最佳的性能。   這篇文章是從一個(gè)名為Gentoo Linux的發(fā)行版的編程說(shuō)明書里面分離出來(lái)的,希望對(duì)大家編譯程序有幫助。

--------------------------------------------------------------------------------
一、1.2版(gcc 2.9.x版)
i386 (Intel), do you really want to install gentoo on that? CHOST="i386-pc-linux-gnu" CFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer"
i486 (Intel), do you really want to install gentoo on that? CHOST="i486-pc-linux-gnu" CFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer"
Pentium, Pentium MMX+, Celeron (Mendocino) (Intel) CHOST="i586-pc-linux-gnu" CFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer"
Pentium Pro/II/III/4, Celeron (Coppermine), Celeron (Willamette?) (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=i686 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i686 -O3 -pipe -fomit-frame-pointer"
Eden C3/Ezra (Via) CHOST="i586-pc-linux-gnu" CFLAGS="-march=i586 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i586 -O3 -pipe -fomit-frame-pointer"
Quote : I did the original gentoo install using 1.2, with gcc 2.95 using -march=i586. i686 won't work.
K6 or beyond (AMD) CHOST="i586-pc-linux-gnu" CFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"
(A Duron will report "Athlon" in its /proc/cpuinfo)
Athlon (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"
For the following, i don't know of any flag that enhance performances..., do you ?
PowerPC CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -pipe -fomit-frame-pointer"
Sparc CHOST="sparc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -pipe -fomit-frame-pointer"
Sparc 64 CHOST="sparc64-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -pipe -fomit-frame-pointer"

二、1.4版(gcc 3.x版):
i386 (Intel), do you really want to install gentoo on that ? CHOST="i386-pc-linux-gnu" CFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i386 -O3 -pipe -fomit-frame-pointer"
i486 (Intel), do you really want to install gentoo on that ? CHOST="i486-pc-linux-gnu" CFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i486 -O3 -pipe -fomit-frame-pointer"
Pentium 1 (Intel) CHOST="i586-pc-linux-gnu" CFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium -O3 -pipe -fomit-frame-pointer"
Pentium MMX (Intel) CHOST="i586-pc-linux-gnu" CFLAGS="-march=pentium-mmx -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium-mmx -O3 -pipe -fomit-frame-pointer"
Pentium PRO (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentiumpro -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentiumpro -O3 -pipe -fomit-frame-pointer"
Pentium II (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
Celeron (Mendocino), aka Celeron1 (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium2 -O3 -pipe -fomit-frame-pointer"
Pentium III (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
Celeron (Coppermine) aka Celeron2 (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer"
Celeron (Willamette?) (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
Pentium 4 (Intel) CHOST="i686-pc-linux-gnu" CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"
Eden C3/Ezra (Via) CHOST="i586-pc-linux-gnu" CFLAGS="-march=i586 -m3dnow -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=i586 -m3dnow -O3 -pipe -fomit-frame-pointer"
quote : the ezra doesn't have any special instructions that you could optimize for, just consider is a K6-3...basically a p2 with 3dnow
K6 (AMD) CHOST="i586-pc-linux-gnu" CFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=k6 -O3 -pipe -fomit-frame-pointer"
K6-2 (AMD) CHOST="i586-pc-linux-gnu" CFLAGS="-march=k6-2 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=k6-2 -O3 -pipe -fomit-frame-pointer"
K6-3 (AMD) CHOST="i586-pc-linux-gnu" CFLAGS="-march=k6-3 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=k6-3 -O3 -pipe -fomit-frame-pointer"
Athlon (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon -O3 -pipe -fomit-frame-pointer"
Athlon-tbird, aka K7 (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon-tbird -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon-tbird -O3 -pipe -fomit-frame-pointer"
Athlon-tbird XP (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
Athlon 4(AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon-4 -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon-4 -O3 -pipe -fomit-frame-pointer"
Athlon XP (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon-xp -O3 -pipe -fomit-frame-pointer"
Athlon MP (AMD) CHOST="i686-pc-linux-gnu" CFLAGS="-march=athlon-mp -O3 -pipe -fomit-frame-pointer" CXXFLAGS="-march=athlon-mp -O3 -pipe -fomit-frame-pointer"
603 (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
603e (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
604 (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
604e (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
750 aka as G3 (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-mcpu=750 -O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-mcpu=750 -O3 -pipe -fomit-frame-pointer -fsigned-char"
Note: do not use -march=
7400, aka G4 (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-mcpu=7400 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec" CXXFLAGS="-mcpu=7400 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
Note: do not use -march=
7450, aka G4 second generation (PowerPC) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-mcpu=7450 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec" CXXFLAGS="-mcpu=7450 -O3 -pipe -fomit-frame-pointer -fsigned-char -maltivec"
Note: do not use -march=
PowerPC (If you don't know which one) CHOST="powerpc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char" CXXFLAGS="-O3 -pipe -fomit-frame-pointer -fsigned-char"
Sparc CHOST="sparc-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -pipe -fomit-frame-pointer"
Sparc 64 CHOST="sparc64-unknown-linux-gnu" CFLAGS="-O3 -pipe -fomit-frame-pointer" CXXFLAGS="-O3 -pipe -fomit-frame-pointer"GCC 使用指南 GCC 使用指南 GCC 使用指南





轉(zhuǎn)載自:http://blog.csdn.net/casularm/archive/2005/03/09/316143.aspx

- 作者: michaelbob 2005年03月20日, 星期日 13:55  回復(fù)(0) |  引用(0) 加入博采

zzGCC使用指南

創(chuàng)建時(shí)間:2000-06-08
文章屬性:轉(zhuǎn)載
文章提交: quack (quack_at_xfocus.org)


GCC使用指南

使用語(yǔ)法:
gcc [ option | filename ]...
g++ [ option | filename ]...

其中 option 為 gcc 使用時(shí)的選項(xiàng)(后面會(huì)再詳述),
而 filename 為欲以 gcc 處理的文件
說(shuō)明:
這 C 與 C++ 的 compiler 已將產(chǎn)生新程序的相關(guān)程序整合起來(lái)。產(chǎn)
生一個(gè)新的程序需要經(jīng)過(guò)四個(gè)階段:預(yù)處理、編譯、匯編,連結(jié),
而這兩個(gè)編譯器都能將輸入的文件做不同階段的處理。雖然原始程序
的擴(kuò)展名可用來(lái)分辨編寫原始程序碼所用的語(yǔ)言,但不同的 compiler
,其預(yù)設(shè)的處理程序卻各不相同:

gcc預(yù)設(shè)經(jīng)由預(yù)處理過(guò)(擴(kuò)展名為.i)的文件為 C 語(yǔ)言,并於程
式連結(jié)階段以 C 的連結(jié)方式處理。

g++預(yù)設(shè)經(jīng)由預(yù)處理過(guò)(擴(kuò)展名為.i)的文件為 C++ 語(yǔ)言,并於程

序連結(jié)階段以 C++ 的連結(jié)方式處理。


原始程序碼的擴(kuò)展名指出所用編寫程序所用的語(yǔ)言,以及相對(duì)應(yīng)的處
理方法:

.cC 原始程序 ; 預(yù)處理、編譯、匯編
.CC++ 原始程序 ; 預(yù)處理、編譯、匯編
.cc C++ 原始程序 ; 預(yù)處理、編譯、匯編
.cxxC++ 原始程序 ; 預(yù)處理、編譯、匯編
.mObjective-C 原始程序 ; 預(yù)處理、編譯、匯編
.i已經(jīng)過(guò)預(yù)處理之 C 原始程序; 編譯、匯編
.ii 已經(jīng)過(guò)預(yù)處理之 C++ 原始程序; 編譯、匯編
.s組合語(yǔ)言原始程序 ; 匯編
.S組合語(yǔ)言原始程序 ; 預(yù)處理、匯編
.h預(yù)處理文件(標(biāo)頭文件) ; (不常出現(xiàn)在指令行)


其他擴(kuò)展名的文件是由連結(jié)程序來(lái)處理,通常有:

.oObject file
.aArchive file


除非編譯過(guò)程出現(xiàn)錯(cuò)誤,否則 "連結(jié)" 一定是產(chǎn)生一個(gè)新程序的最
後階段。然而你也可以以 -c、-s 或 -E 等選項(xiàng),將整個(gè)過(guò)程自四
個(gè)階段中的其中一個(gè)停止。在連結(jié)階段,所有與原始碼相對(duì)應(yīng)的
.o 文件、程序庫(kù)、和其他無(wú)法自文件名辨明屬性的文件(包括不以 .o
為擴(kuò)展名的 object file 以及擴(kuò)展名為 .a 的 archive file)都會(huì)
交由連結(jié)程序來(lái)處理(在指令行將那些文件當(dāng)作連結(jié)程序的參數(shù)傳給
連結(jié)程序)。


選項(xiàng):
不同的選項(xiàng)必須分開(kāi)來(lái)下:例如 `-dr' 這個(gè)選項(xiàng)就與 `-d -r' 大
不相同。

絕大部份的 `-f' 及 `-W' 選項(xiàng)都有正反兩種形式:-fname 及
-fno-name (或 -Wname 及 -Wno-name)。以下只列出非預(yù)設(shè)的那個(gè)
形式。

以下是所有選項(xiàng)的摘要。以形式來(lái)分類。選項(xiàng)的意義將另辟小節(jié)說(shuō)
明。

一般性(概略、常用的)選項(xiàng)
-c -S -E -o file -pipe -v -x language

程序語(yǔ)言選項(xiàng)
-ansi -fall-virtual -fcond-mismatch
-fdollars-in-identifiers -fenum-int-equiv
-fexternal-templates -fno-asm -fno-builtin
-fno-strict-prototype -fsigned-bitfields
-fsigned-char -fthis-is-variable
-funsigned-bitfields -funsigned-char
-fwritable-strings -traditional -traditional-cpp
-trigraphs

編譯時(shí)的警告選項(xiàng)
-fsyntax-only -pedantic -pedantic-errors -w -W
-Wall -Waggregate-return -Wcast-align -Wcast-qual
-Wchar-subscript -Wcomment -Wconversion
-Wenum-clash -Werror -Wformat -Wid-clash-len
-Wimplicit -Winline -Wmissing-prototypes
-Wmissing-declarations -Wnested-externs -Wno-import
-Wparentheses -Wpointer-arith -Wredundant-decls
-Wreturn-type -Wshadow -Wstrict-prototypes -Wswitch
-Wtemplate-debugging -Wtraditional -Wtrigraphs
-Wuninitialized -Wunused -Wwrite-strings

除錯(cuò)選項(xiàng)
-a -dletters -fpretend-float -g -glevel -gcoff
-gxcoff -gxcoff+ -gdwarf -gdwarf+ -gstabs -gstabs+
-ggdb -p -pg -save-temps -print-file-name=library
-print-libgcc-file-name -print-prog-name=program

最佳化選項(xiàng)
-fcaller-saves -fcse-follow-jumps -fcse-skip-blocks
-fdelayed-branch -felide-constructors
-fexpensive-optimizations -ffast-math -ffloat-store
-fforce-addr -fforce-mem -finline-functions
-fkeep-inline-functions -fmemoize-lookups
-fno-default-inline -fno-defer-pop
-fno-function-cse -fno-inline -fno-peephole
-fomit-frame-pointer -frerun-cse-after-loop
-fschedule-insns -fschedule-insns2
-fstrength-reduce -fthread-jumps -funroll-all-loops
-funroll-loops -O -O2

預(yù)處理選項(xiàng)
-Aassertion -C -dD -dM -dN -Dmacro[=defn] -E -H
-idirafter dir -include file -imacros file -iprefix
file -iwithprefix dir -M -MD -MM -MMD -nostdinc -P
-Umacro -undef

匯編程序選項(xiàng)
-Wa,option

連結(jié)程序選項(xiàng)
-llibrary -nostartfiles -nostdlib -static -shared
-symbolic -Xlinker option -Wl,option -u symbol

目錄選項(xiàng)
-Bprefix -Idir -I- -Ldir

Target Options
-bmachine -V version

與機(jī)器(平臺(tái))相關(guān)的選項(xiàng)
M680x0 Options
-m68000 -m68020 -m68020-40 -m68030 -m68040 -m68881
-mbitfield -mc68000 -mc68020 -mfpa -mnobitfield
-mrtd -mshort -msoft-float

VAX Options
-mg -mgnu -munix

SPARC Options
-mepilogue -mfpu -mhard-float -mno-fpu
-mno-epilogue -msoft-float -msparclite -mv8
-msupersparc -mcypress

Convex Options
-margcount -mc1 -mc2 -mnoargcount

AMD29K Options
-m29000 -m29050 -mbw -mdw -mkernel-registers
-mlarge -mnbw -mnodw -msmall -mstack-check
-muser-registers

M88K Options
-m88000 -m88100 -m88110 -mbig-pic
-mcheck-zero-division -mhandle-large-shift
-midentify-revision -mno-check-zero-division
-mno-ocs-debug-info -mno-ocs-frame-position
-mno-optimize-arg-area -mno-serialize-volatile
-mno-underscores -mocs-debug-info
-mocs-frame-position -moptimize-arg-area
-mserialize-volatile -mshort-data-num -msvr3 -msvr4
-mtrap-large-shift -muse-div-instruction
-mversion-03.00 -mwarn-passed-structs

RS6000 Options
-mfp-in-toc -mno-fop-in-toc

RT Options
-mcall-lib-mul -mfp-arg-in-fpregs -mfp-arg-in-gregs
-mfull-fp-blocks -mhc-struct-return -min-line-mul
-mminimum-fp-blocks -mnohc-struct-return

MIPS Options
-mcpu=cpu type -mips2 -mips3 -mint64 -mlong64
-mlonglong128 -mmips-as -mgas -mrnames -mno-rnames
-mgpopt -mno-gpopt -mstats -mno-stats -mmemcpy
-mno-memcpy -mno-mips-tfile -mmips-tfile
-msoft-float -mhard-float -mabicalls -mno-abicalls
-mhalf-pic -mno-half-pic -G num -nocpp

i386 Options
-m486 -mno-486 -msoft-float -mno-fp-ret-in-387

HPPA Options
-mpa-risc-1-0 -mpa-risc-1-1 -mkernel -mshared-libs
-mno-shared-libs -mlong-calls -mdisable-fpregs
-mdisable-indexing -mtrailing-colon

i960 Options
-mcpu-type -mnumerics -msoft-float
-mleaf-procedures -mno-leaf-procedures -mtail-call
-mno-tail-call -mcomplex-addr -mno-complex-addr
-mcode-align -mno-code-align -mic-compat
-mic2.0-compat -mic3.0-compat -masm-compat
-mintel-asm -mstrict-align -mno-strict-align
-mold-align -mno-old-align

DEC Alpha Options
-mfp-regs -mno-fp-regs -mno-soft-float -msoft-float

System V Options
-G -Qy -Qn -YP,paths -Ym,dir

Code Generation Options
-fcall-saved-reg -fcall-used-reg -ffixed-reg
-finhibit-size-directive -fnonnull-objects
-fno-common -fno-ident -fno-gnu-linker
-fpcc-struct-return -fpic -fPIC
-freg-struct-returno -fshared-data -fshort-enums
-fshort-double -fvolatile -fvolatile-global
-fverbose-asm

PRAGMAS
Two`#pragma'directivesaresupported for GNU C++, to
permit using the same header file for two purposes:asa
definitionofinterfaces to a given object class, and as
the full definition of the contents of that objectclass.

#pragma interface
(C++only.) Usethisdirective in header files
that define object classes, to save spaceinmost
oftheobject files that use those classes.Nor-
mally, local copies of certain information(backup
copies of inline member functions, debugging infor-
mation, and the internal tables that implement vir-
tualfunctions)mustbe kept in each object file
that includes class definitions.You can usethis
pragmatoavoidsuch duplication.When a header
file containing `#pragma interface' is includedin
acompilation, this auxiliary information will not
be generated (unless the main input source file it-
selfuses `#pragma implementation').Instead, the
object files will contain references to be resolved
at link time.

#pragma implementation

#pragma implementation "objects.h"
(C++only.)Use this pragma in a main input file,
when you wantfulloutputfromincludedheader
filesto be generated (and made globally visible).
The includedheaderfile,inturn,shoulduse
`#pragmainterface'.Backup copies of inline mem-
ber functions, debugging information, andthein-
ternaltablesused to implement virtual functions
are all generated in implementation files.

If you use `#pragma implementation' withnoargu-
ment,itapplies to an include file with the same
basename asyoursourcefile;forexample,in
`allclass.cc',`#pragmaimplementation' by itself
is equivalentto`#pragmaimplementation
"allclass.h"'.Use the string argument if you want
a single implementation file to includecodefrom
multiple header files.

Thereis no way to split up the contents of a sin-
gle header file into multiple implementation files.

文件說(shuō)明
file.c C source file
file.h C header (preprocessor) file
file.i 經(jīng)預(yù)處理過(guò)的 C source file
file.C C++ source file
file.ccC++ source file
file.cxx C++ source file
file.m Objective-C source file
file.s assembly language file
file.o object file
a.outlink edited output
TMPDIR/cc* temporary files
LIBDIR/cpp preprocessor
LIBDIR/cc1 compiler for C
LIBDIR/cc1plus compiler for C++
LIBDIR/collect linker front end needed on some machines
LIBDIR/libgcc.aGCC subroutine library
/lib/crt[01n].ostart-up routine
LIBDIR/ccrt0 additional start-up routine for C++
/lib/libc.astandard C library, 參閱 man page intro(3)
/usr/include standard directory for #include files
LIBDIR/include standard gcc directory for #include files
LIBDIR/g++-include additional g++ directory for #include

LIBDIR is usually /usr/local/lib/machine/version.
TMPDIR comes from the environment variable TMPDIR (default
/usr/tmp if available, else /tmp).

gcc


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 久久国产国内精品对话对白 | 欧美一级久久久久久久久大 | 99热这里只有精品一区二 | 欧美一二区视频 | 国产成人禁片免费观看 | 亚洲一区二区在线免费观看 | 亚洲欧美日韩中文字幕在线一区 | 久久草视频在线 | 色狠狠狠色噜噜噜综合网 | 五月天激情亚洲婷婷在线 | 天天透天天操 | 欧美激情久久久久久久久 | 国产一起色一起爱 | 欧美日韩成人高清色视频 | www.欧美成人| 免费在线观看的毛片 | 天天射天天怕 | 欧美同房免姿势108费视频 | 免费观看呢日本天堂视频 | 一区二区福利视频 | 国产女人18一级毛片视频 | 香蕉视频黄色在线观看 | 中文字幕免费在线看线人动作大片 | 国产精品不卡视频 | 性刺激的欧美三级视频 | 日韩成人伦理 | 中文在线免费视频 | 人人爰人人人人人鲁 | 天天干天天操天天干 | 国产美女午夜精品福利视频 | 午夜精品福利在线 | 717影院理论午夜伦八戒 | 香蕉视频黄在线观看 | 91精品国产色综合久久不 | 中国大陆高清aⅴ毛片 | 国产成人精品综合网站 | 欧美午夜在线观看 | 四虎亚洲 | a免费国产一级特黄aa大 | 欧美一区二区三区免费观看视频 | 鲁啊鲁在线视频 |