From where i stand,

        there are two programmig languages in the world,

            which is C lang and the other.

 

编译(compile)

  • 预处理(也称预编译,Preprocessing)
  • 编译(Compilation)
  • 汇编 (Assembly)
  • 连接(Linking)

GCC参考

gcc - GNU project C and C++ compiler

If you only want some of the stages of compilation, you can use -x (or filename suffixes) to tell gcc where to start, and one of the options -c, -S, or -E to say where gcc is to stop. Note that some combinations (for example, -x cpp-output -E) instruct gcc to do nothing at all.

  • -E Stop after the preprocessing stage; do not run the compiler proper.
  • -S Stop after the stage of compilation proper; do not assemble.
  • -c Compile or assemble the source files, but do not link.
  • -o targetfile Place output in file targetfile.



 [root@standby gcc]# date +%F_%H:%M:%S
--29_23::
[root@standby gcc]# pwd
/data/gcc
[root@standby gcc]# ll
total
-rw-r--r-- root root Nov : hello.c
[root@standby gcc]# cat hello.c
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return ;
}
[root@standby gcc]#
[root@standby gcc]# file hello.c
hello.c: ASCII C program text
[root@standby gcc]#

预处理/Preprocessing

'删除注释和";"、进行宏替换、将头文件插入进来、条件编译等'
 [root@standby gcc]# gcc -E hello.c -o hello.i
[root@standby gcc]# ll
total
-rw-r--r-- root root Nov : hello.c
-rw-r--r-- root root Nov : hello.i
[root@standby gcc]# file hello.i
hello.i: ASCII C program text
[root@standby gcc]#

编译/Compilation

'生成汇编代码'
 [root@standby gcc]# gcc -S hello.i -o hello.s
[root@standby gcc]# ll
total
-rw-r--r-- root root Nov : hello.c
-rw-r--r-- root root Nov : hello.i
-rw-r--r-- root root Nov : hello.s
[root@standby gcc]# file hello.s
hello.s: ASCII assembler program text
[root@standby gcc]#

汇编/Assembly

'生成目标文件'
 [root@standby gcc]# gcc -c hello.s -o hello.o
[root@standby gcc]# ll
total
-rw-r--r-- root root Nov : hello.c
-rw-r--r-- root root Nov : hello.i
-rw-r--r-- root root Nov : hello.o
-rw-r--r-- root root Nov : hello.s
[root@standby gcc]# file hello.o
hello.o: ELF -bit LSB relocatable, x86-, version (SYSV), not stripped
[root@standby gcc]#

连接/Linking

'生成可执行文件'
 [root@standby gcc]# gcc hello.o -o helloworld
[root@standby gcc]# ll
total
-rw-r--r-- root root Nov : hello.c
-rw-r--r-- root root Nov : hello.i
-rw-r--r-- root root Nov : hello.o
-rw-r--r-- root root Nov : hello.s
-rwxr-xr-x root root Nov : helloworld
[root@standby gcc]# file helloworld
helloworld: ELF -bit LSB executable, x86-, version (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6., not stripped
[root@standby gcc]#
[root@standby gcc]# ./helloworld
Hello World!
[root@standby gcc]#



汇编代码

 [root@standby gcc]# cat hello.s
.file "hello.c"
.section .rodata
.LC0:
.string "Hello World!"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset
.cfi_offset , -
movq %rsp, %rbp
.cfi_def_cfa_register
movl $.LC0, %edi
call puts
movl $, %eax
leave
.cfi_def_cfa ,
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.4.7 20120313 (Red Hat 4.4.7-17)"
.section .note.GNU-stack,"",@progbits
[root@standby gcc]#

C 编译过程浅析的更多相关文章

  1. C程序编译过程浅析

    前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接”,主要根据其中的内容简单总结一下C程序编译的过程吧. 我现在一般都是用gcc,所以自然以GCC编译hellworld ...

  2. C程序编译过程浅析(转)

    前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接”,主要根据其中的内容简单总结一下C程序编译的过程吧. 我现在一般都是用gcc,所以自然以GCC编译hellworld ...

  3. C程序编译过程浅析【转】

    转自:http://blog.csdn.net/koudaidai/article/details/8092647 前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接” ...

  4. OpenJDK源码研究笔记(十一):浅析Javac编译过程中的抽象语法树(IfElse,While,Switch等语句的抽象和封装)

    浅析OpenJDK源码编译器Javac的语法树包com.sun.source.tree. 抽象语法树,是编译原理中的经典问题,有点难,本文只是随便写写. 0.赋值语句 public interface ...

  5. Linux入门——开机启动过程浅析

    Linux开机启动过程浅析 Introduction 开机启动过程分为以下6个步骤,分别是BIOS, MBR, GRUB, Kernel, Init, RunLevel, RunDefinition ...

  6. GCC编译流程浅析

    GCC-GCC编译流程浅析 序言 对于大多数程序员而言,大家都知道gcc是什么,但是如果不接触到linux平台下的开发,鲜有人真正了解gcc的编译流程,因为windows+IDE的开发模式简直是一条龙 ...

  7. Android工程的编译过程

    现在很多人想对Android工程的编译和打包进行自动化,比如建立每日构建系统.自动生成发布文件等等.这些都需要我们对Android工程的编译和打包有一个深入的理解,至少要知道它的每一步都做了什么,需要 ...

  8. GCC编译过程

    以下是C程序一般的编译过程: gcc的编译流程分为四个步骤,分别为:· 预处理(Pre-Processing) 对C语言进行预处理,生成*.i文件.· 编译(Compiling) 将上一步生成的*.i ...

  9. Linux系统GCC常用命令和GCC编译过程描述

    前言: GCC 原名为 GNU C 语言编译器(GNU C Compiler),因为它原本只能处理 C语言.GCC 很快地扩展,变得可处理 C++.后来又 扩展能够支持更多编程语言,如Fortran. ...

随机推荐

  1. Docker安装指定版本

    今天新增一个Docker服务器,Docker安装顺利,启动hello-world测试的时候却出现了问题: $ docker run hello-worldUnable to find image 'h ...

  2. ES6定型数组

    前面的话 定型数组是一种用于处理数值类型(正如其名,不是所有类型)数据的专用数组,最早是在WebGL中使用的,WebGL是OpenGL ES 2.0的移植版,在Web 页面中通过 <canvas ...

  3. 黄金Corner

    春水初生 春林初盛 春风十里 你在哪里

  4. ajax 提交数组 泛型集合(二)

    最近在项目中,使用 mvc架构,model层使用code first 碰见一个问题,前台json传递数据给后台action的复杂对象,发现复杂对象中的list范型集合并没有获取到数据. 研究半天,终于 ...

  5. LOJ2540 [PKUWC2018] 随机算法 【状压DP】

    题目分析: 听说这题考场上能被$ O(4^n) $的暴力水过,难不成出题人是毕姥爷? 首先思考一个显而易见的$ O(n^2*2^n) $的暴力DP.一般的DP都是考虑最近的加入了哪个点,然后删除后递归 ...

  6. 03 自学Aruba之2.4GHz及5GHz无线信道

    点击返回:自学Aruba之路点击返回:自学Aruba集锦 03 自学Aruba之2.4GHz及5GHz无线信道 1.  2.4GHz信道 在各国家授权使用的频段: 信道号 中心频率(GHz) 美国FC ...

  7. 自学Linux Shell3.2-切换目录命令cd

    点击返回 自学Linux命令行与Shell脚本之路 3.2-切换目录命令cd 当登录系统并获得shell命令提示符后,你通常位于自己的主目录中. 使用pwd命令验证: pwd命令以绝对路径的方式显示用 ...

  8. 自学Zabbix3.11-宏Macros

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix3.11-宏Macros zabbix宏变量让zabbix变得更灵活,它根据一系列 ...

  9. HNOI2018题解

    在此处输入标题 标签(空格分隔): 未分类 重做了一遍,本来以为很快的,结果搞了一天... 寻宝游戏 可以发现只有\(\&0\)和\(|1\)会对答案有影响 那么对于每一位,我们只要知道最后一 ...

  10. 全面解析Java类加载器

    深入理解和探究Java类加载机制---- 1.java.lang.ClassLoader类介绍 java.lang.ClassLoader类的基本职责就是根据一个指定的类的名称,找到或者生成其对应的字 ...