代码文件-预编译-编译-汇编-链接-可执行程序

HelloWorld.c文件:

#include <stdio.h>

int main()
{
        printf("Hello World\n");
        return 0;
}


1、预编译

gcc -E HelloWorld.c -o HelloWorld.i

将宏定义和include展开


[intf@vms1 liukun]$ more HelloWorld.i
# 1 "HelloWorld.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "HelloWorld.c"
# 1 "/usr/include/stdio.h" 1 3 4
# 28 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 329 "/usr/include/features.h" 3 4
# 1 "/usr/include/sys/cdefs.h" 1 3 4
# 313 "/usr/include/sys/cdefs.h" 3 4
# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 314 "/usr/include/sys/cdefs.h" 2 3 4
# 330 "/usr/include/features.h" 2 3 4
# 352 "/usr/include/features.h" 3 4
# 1 "/usr/include/gnu/stubs.h" 1 3 4

# 1 "/usr/include/bits/wordsize.h" 1 3 4
# 5 "/usr/include/gnu/stubs.h" 2 3 4

# 1 "/usr/include/gnu/stubs-64.h" 1 3 4
# 10 "/usr/include/gnu/stubs.h" 2 3 4
# 353 "/usr/include/features.h" 2 3 4
# 29 "/usr/include/stdio.h" 2 3 4

......................

# 844 "/usr/include/stdio.h" 3 4


# 2 "HelloWorld.c" 2


int main()
{
 printf("Hello World\n");
 return 0;
}


2、编译

gcc -S HelloWorld.i -o HelloWorld.s

生成汇编代码

[intf@vms1 liukun]$ more  HelloWorld.s
        .file   "HelloWorld.c"
        .section        .rodata
.LC0:
        .string "Hello World"
        .text
.globl main
        .type   main, @function
main:
.LFB2:
        pushq   %rbp
.LCFI0:
        movq    %rsp, %rbp
.LCFI1:
        movl    $.LC0, %edi
        call    puts
        movl    $0, %eax
        leave
        ret
.LFE2:
        .size   main, .-main
        .section        .eh_frame,"a",@progbits
.Lframe1:
        .long   .LECIE1-.LSCIE1
.LSCIE1:
        .long   0x0
        .byte   0x1
        .string "zR"
        .uleb128 0x1

3、汇编

gcc -c HelloWorld.s -o HelloWorld.o

生成ELF格式的目标代码

[intf@vms1 liukun]$ file HelloWorld.o
HelloWorld.o: ELF 64-bit LSB relocatable, AMD x86-64, version 1 (SYSV), not stripped


4、链接

忘了怎么写了,下次补上



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值