Linux下helloworld的简单编译过程
来源:互联网 发布:java jdbc连接池使用 编辑:程序博客网 时间:2024/06/06 18:34
我们在使用gcc生成可执行程序的时候,一般是命令: gcc *.c, 生成可执行文件a.out
其实过程可以分为4个步骤,分别是预处理,编译,汇编和链接。下面以最基本的helloworld来简单了解一下编译的过程。
1.预编译
预编译又称为预处理,是做些代码文本的替换工作。
处理#开头的指令,比如拷贝#include包含的文件代码,#define宏定义的替换,条件编译等,就是为编译做的预备工作的阶段,主要处理#开始的预编译指令。
gcc -E hello.c -o hello.i
生成的hello.i仍然是个文本文件
cat@lenovo:~/blog/0718$ lshello.ccat@lenovo:~/blog/0718$ gcc -E hello.c -o hello.icat@lenovo:~/blog/0718$ file hello.ihello.i: UTF-8 Unicode C program text
2.编译
把用高级程序设计语言书写的源程序,翻译成汇编语言
cat@lenovo:~/blog/0718$ lshello.c hello.icat@lenovo:~/blog/0718$ gcc -S hello.icat@lenovo:~/blog/0718$ lshello.c hello.i hello.scat@lenovo:~/blog/0718$ cat hello.s .file "hello.c" .section .rodata.LC0: .string "hello world" .text .globl main .type main, @functionmain:.LFB0: .cfi_startproc pushl %ebp .cfi_def_cfa_offset 8 .cfi_offset 5, -8 movl %esp, %ebp .cfi_def_cfa_register 5 andl $-16, %esp subl $16, %esp movl $.LC0, (%esp) call puts movl $0, %eax leave .cfi_restore 5 .cfi_def_cfa 4, 4 ret .cfi_endproc.LFE0: .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3" .section .note.GNU-stack,"",@progbits
3.汇编
这个过程把汇编语言翻译成机器语言
cat@lenovo:~/blog/0718$ lshello.c hello.i hello.scat@lenovo:~/blog/0718$ gcc -c hello.scat@lenovo:~/blog/0718$ lshello.c hello.i hello.o hello.scat@lenovo:~/blog/0718$ file hello.ohello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
4.链接
将生成的目标文件和其所依赖的库文件进行连接,生成一个可执行文件
cat@lenovo:~/blog/0718$ gcc hello.ocat@lenovo:~/blog/0718$ lsa.out hello.c hello.i hello.o hello.scat@lenovo:~/blog/0718$ ./a.out hello world
0 0
- Linux下helloworld的简单编译过程
- Contiki 了解(2)-HelloWorld的编译过程
- Linux下bti库的编译过程
- 难以忍受的Linux下编译过程
- Linux下GCC编译的四个过程
- Linux下GCC编译的四个过程
- Linux下源程序的编译过程
- Linux下编译C文件的过程
- Linux下Gcc 的编译过程
- linux下c程序的编译过程
- linux下java程序的编译过程
- Linux下程序的编译过程
- Tiny6410 简单的交叉编译helloworld
- linux下的helloworld程序
- ffmpeg编译过程(二)-->Linux下的编译常用命令
- linux下带有CDT的Eclipse的helloworld编译错误的解决方法
- linux 交叉编译的HelloWorld【1】
- ACE在Windows下的简单编译过程
- Linux NFS服务器的安装与配置
- 欢迎使用CSDN-markdown编辑器
- 魅族手机无法连接到MAC使用abd
- 城域网IPv6过渡技术―DS-lite的业务流程
- ExtJS加载iframe后回调的另一个思路
- Linux下helloworld的简单编译过程
- jquery选中表格的某行变色
- opencv3.0 cmake出错问题
- 开放Linux端口
- CentOS6.5配置IP地址的三种方法
- C# 修改 Bitmap 尺寸 避免内存溢出
- 智能手机屏幕尺寸和分辨率一览表
- “道德”,究竟是保镖还是杀手?
- Event Bus在安卓开发中的使用场景和技巧