C语言编译过程:预编译、编译、汇编、链接
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C语言编译过程:预编译、编译、汇编、链接,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1946字,纯文字阅读大概需要3分钟。
内容图文
![C语言编译过程:预编译、编译、汇编、链接](/upload/InfoBanner/zyjiaocheng/619/88a1ae43d9ea45189d7a1dbb6c528436.jpg)
目录
命令
$
gcc -E hello.c -o hello.i
$gcc -S hello.i -o hello.s
$gcc -c hello.s -o hello.o
$gcc hello.o -o hello
$
$./hello
hello world!
pre-compiled here!
static __always_inline void func
C程序
// hello.c
#include <stdio.h>
#define PREPROCESSING "Pre-processing"
static __always_inline void func(void)
{
printf("static __always_inline void func\n");
return;
}
int main(int argc, const char *argv[])
{
printf("Hello world!\n");
printf("%s here!\n", PREPROCESSING);
func();
return 0;
}
预处理(Preprocessing)
将宏、头文件等代码替换
到被调用处,不检查语法
。
预处理结果就是将stdio.h 文件中的内容插入到test.c中了。
预处理文件格式为.i
// hello.i
/* 内容省略stdio.h */
# 2 "hello.c" 2
static __inline __attribute__ ((__always_inline__)) void func(void)
{
printf("static __always_inline void func\n");
return;
}
int main(int argc, const char *argv[])
{
printf("hello world!\n");
printf("%s here!\n", "pre-processing");
func();
return 0;
}
编译(Compilation)
将c语言代码编译为最高效的汇编语言代码
,并检查语法
。
汇编文件格式为.s
// hello.s
.file "hello.c"
.section .rodata
.LC0:
.string "hello world!"
.LC1:
.string "%s here!\n"
.LC2:
.string "pre-processing"
.align 8
.LC3:
.string "static __always_inline void func"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
subq $16, %rsp
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
movl $.LC0, %edi
call puts
movl $.LC1, %eax
movl $.LC2, %esi
movq %rax, %rdi
movl $0, %eax
call printf
movl $.LC3, %edi
call puts
movl $0, %eax
leave
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7"
.section .note.GNU-stack,"",@progbits
汇编(Assembly)
将汇编代码
编译为目标文件
。
目标文件格式为.o
链接(Linking)
将程序的目标文件
与所需的所有附加的目标文件
连接起来,最终生成可执行文件
。附加的目标文件包括静态连接库
和动态连接库
。
此步骤最终生成可执行程序
。
内容总结
以上是互联网集市为您收集整理的C语言编译过程:预编译、编译、汇编、链接全部内容,希望文章能够帮你解决C语言编译过程:预编译、编译、汇编、链接所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。