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. CRM模块

  2. delphi创建动态菜单

    1.动态生成菜单项 varFirstItem: TMenuItem;SecondItem: TMenuItem; begin FirstItem := TMenuItem.Create(Self); ...

  3. BZOJ3261最大异或和——主席树

    题目描述 给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.Ax:添加操作,表示在序列末尾添加一个数x,序列的长度N+1. 2.Qlrx:询问操作,你需要找到一个位置p ...

  4. BZOJ2795&2890&3647[Poi2012]A Horrible Poem——hash

    题目描述 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节.如果字符串B是字符串A的循环节,那么A可以由B重复若干次得到. 输入 第一行一个正整数n (n<= ...

  5. JavaScript--XML DOM 总结

    XML DOM 2018-09-04 XML简介 1.什么是XML XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML ...

  6. Hopcroft-Carp 算法模板 自用

    #include <iostream> #include <cstdio> #include <cstring> #include <queue> #d ...

  7. Educational Codeforces Round 3 C. Load Balancing

    C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. 19 Zabbix web监控实例

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 9 Zabbix web监控实例 通过前面的介绍你已经了解Web scenario的配置,下面我们 ...

  9. 自学Zabbix8.1 Regular expressions 正则表达式

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix8.1 Regular expressions 正则表达式 1. 配置 点击Adm ...

  10. ANDROID OptionMenu 菜单列表

    package com.app.menu; import android.os.Bundle; import android.app.Activity; import android.content. ...