C语言 预处理 编译 汇编 链接

本文详细介绍了C语言的编译过程,包括预处理(宏替换、删注释、展开包含文件)、编译(生成汇编指令代码文件)、汇编(翻译成二进制目标文件)和链接(将目标文件与库文件链接成可执行文件)。预处理使用`-E`选项,编译使用`-S`选项,汇编使用`-c`选项,链接最终生成可执行文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C语言 预处理 编译 汇编 链接

gcc help

$ gcc --help

-save-temps              Do not delete intermediate files
-E                       Preprocess only; do not compile, assemble or link
-S                       Compile only; do not assemble or link
-c                       Compile and assemble, but do not link
-o <file>                Place the output into <file>

对c文件,想要保留中间文件,执行下面命令:

$ gcc -Wall -save-temps hello.c

// 会生成文件
hello.i
hello.s
hello.o
a.out

下面一一说明。

(1)Pre-processing

-E    Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.
      Input files that don't require preprocessing are ignored.

预处理的任务是:

  • Macro substitution 宏(#define)替换
  • Comments are stripped off 删注释
  • Expansion of the included files 展开包含文件(#include)的声明

预处理可以理解成:把你所写的源代码转换成扩展的完整源代码。

What the preprocessor does is convert the source code file you write into another source code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值