C語言基礎 -2 gcc,vim

[root@localhost c]# cat hello.c
#include <stdio.h>
#include<stdlib.h>

int main(void)
{
        printf("Hello world\n");

        exit(0);
}

[root@localhost ~]# gcc -v
gcc version 4.8.5 20150623 
預處理
[root@localhost c]# gcc -E hello.c > hello.i
以#開頭的內容,都是在預處理階段被解決掉

編譯,默認生成.s文件
[root@localhost c]# gcc -S  hello.i

 經過編譯,變成了彙編語言

[root@localhost c]# cat hello.s
        .file   "hello.c"
        .section        .rodata
.LC0:
        .string "Hello world"
        .text
        .globl  main
        .type   main, @function
main:
.LFB2:
        .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, %edi
        call    exit
        .cfi_endproc
.LFE2:
        .size   main, .-main
        .ident  "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-39)"
        .section        .note.GNU-stack,"",@progbits
彙編:默認生成.o,目標文件
[root@localhost c]# gcc -c hello.s
[root@localhost c]# ls
hello.c  hello.i  hello.o  hello.s  test.c

鏈接:生成可執行文件
[root@localhost c]# gcc -o hello.o hello
[root@localhost c]# ls
hello  hello.c  hello.i  hello.s  test.c
[root@localhost c]# ./hello  運行當前路徑下的hello
Hello world
生成a.out
[root@localhost c]# gcc hello.c   
[root@localhost c]# ls
a.out  hello  hello.c  hello.i  hello.s  test.c
[root@localhost c]# gcc hello.c -o myhello
[root@localhost c]# ls
a.out  hello  hello.c  hello.i  hello.s  myhello  test.c
[root@localhost c]# ./myhello 
Hello world

vi使用技巧:

光標指向exit,shit + k,則自動切到幫助手冊,按q,q回到代碼

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章