0.原始碼
#include
intmain()
gcc -e demo.c -o demo.i
1.預編譯
不做其他處理,輸出檔案為demo.i
2.編譯階段,只進行編譯,不做其他,生成乙個彙編檔案
gcc -s demo.i -o demo.s
學習組合語言的時候,可以對照c語言機器彙編**
.file "demo.c"
.section .rodata
.lc0:
.string "hello world!"
.text
.globl main
.type main, @function
main:
.lfb0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.lc0, %edi
call puts
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret.cfi_endproc
.lfe0:
.size main, .-main
.ident "gcc: (gnu) 4.8.5 20150623 (red hat 4.8.5-36)"
.section .note.gnu-stack,"",@progbits
3.彙編階段,這個階段是吧彙編**翻譯為cpu可以識別的二進位制**
引數c的意思是只進行編譯
gcc -c demo.s -o demo.o
4.鏈結階段
對於乙個檔案來說,這步就是把.o檔案和庫檔案結合(有些是需要很多原始檔的)
gcc demo.o -o demo
生成可執行檔案 demo
linux]
->
./demo
hello world!
gcc生成的格式有三種,a.out ,coff,elf(這個格式比較新) GCC編譯流程分析
1.預處理結點 gcc的選項 e 可以使編譯器在預處理結束時就停止編譯 gcc e o hello.i hello.c 字尾名 i 的檔案是經過預處理的c原始程式。2.編譯階段 gcc的選項 s 能使編譯器在進行完編譯之前就停止。3.彙編階段 彙編階段把編譯階段生成的 s 檔案生成目標檔案,在此使用...
gcc編譯流程
可以利用gcc的引數來控制執行的過程,這樣就可以更深入的了解編譯c程式的過程。下面將通過對乙個程式的編譯來演示整個過程。includeint main 1 預處理 編譯器將c程式的標頭檔案編譯進來,還有巨集的替換,可以用gcc的引數 e來參看。命令 gcc e hello.c o hello.i 作...
gcc編譯流程
步驟命令 說明預處理 gcc e hello.c o hello.i 1.將所有 define刪除,並且展開所有的巨集定義 2.處理所有的條件預編譯指令,如 if ifdef undef ifndef endif elif 3.處理 include,將包含的檔案插入到此處,這是乙個遞迴的過程 4.刪...