C 编译过程浅析
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 - 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 targetfilePlace 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 编译过程浅析的更多相关文章
- C程序编译过程浅析
前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接”,主要根据其中的内容简单总结一下C程序编译的过程吧. 我现在一般都是用gcc,所以自然以GCC编译hellworld ...
- C程序编译过程浅析(转)
前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接”,主要根据其中的内容简单总结一下C程序编译的过程吧. 我现在一般都是用gcc,所以自然以GCC编译hellworld ...
- C程序编译过程浅析【转】
转自:http://blog.csdn.net/koudaidai/article/details/8092647 前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接” ...
- OpenJDK源码研究笔记(十一):浅析Javac编译过程中的抽象语法树(IfElse,While,Switch等语句的抽象和封装)
浅析OpenJDK源码编译器Javac的语法树包com.sun.source.tree. 抽象语法树,是编译原理中的经典问题,有点难,本文只是随便写写. 0.赋值语句 public interface ...
- Linux入门——开机启动过程浅析
Linux开机启动过程浅析 Introduction 开机启动过程分为以下6个步骤,分别是BIOS, MBR, GRUB, Kernel, Init, RunLevel, RunDefinition ...
- GCC编译流程浅析
GCC-GCC编译流程浅析 序言 对于大多数程序员而言,大家都知道gcc是什么,但是如果不接触到linux平台下的开发,鲜有人真正了解gcc的编译流程,因为windows+IDE的开发模式简直是一条龙 ...
- Android工程的编译过程
现在很多人想对Android工程的编译和打包进行自动化,比如建立每日构建系统.自动生成发布文件等等.这些都需要我们对Android工程的编译和打包有一个深入的理解,至少要知道它的每一步都做了什么,需要 ...
- GCC编译过程
以下是C程序一般的编译过程: gcc的编译流程分为四个步骤,分别为:· 预处理(Pre-Processing) 对C语言进行预处理,生成*.i文件.· 编译(Compiling) 将上一步生成的*.i ...
- Linux系统GCC常用命令和GCC编译过程描述
前言: GCC 原名为 GNU C 语言编译器(GNU C Compiler),因为它原本只能处理 C语言.GCC 很快地扩展,变得可处理 C++.后来又 扩展能够支持更多编程语言,如Fortran. ...
随机推荐
- Qt__主窗口、菜单和工具条(QMainWindow,QMenu,QToolBar)
转自豆子空间 主窗口 Qt的GUI程序有一个常用的顶层窗口,叫做MainWindow.MainWindow继承自QMainWindow.QMainWindow窗口分成几个主要的区域: 最上面是Wind ...
- 关于linux上文件无法正确显示中文的情况解决
其实有遇到过多次,而且还有几次是css在预编译的时候,系统编码不对也会报错. 贴一个写的还不错的文章:http://www.360doc.com/content/11/0728/09/7102324_ ...
- jQuery 簡介
jQuery:是一個js庫,可以極大地簡化編程,“寫得少做得多”. jquery的作用: 挑選元素.操作屬性.事件函數.動畫和效果.ajax: jQuery庫:google和microsoft都支持, ...
- python之tkinter使用-单级菜单
# 菜单功能说明:单级菜单 import tkinter as tk root = tk.Tk() root.title('菜单选择') root.geometry('200x60') # 设置窗口大 ...
- ubuntu 安装 postgresql
安装环境: Ubuntu 10.04-desktop-i386 PostgreSQL 8.4 1. 安装PostgreSQL 输入如下命令 sudo apt-get install postgresq ...
- Codeforces976E Well played! 【贪心】
题目分析: 由于乘二的收获很大,所以我们可以证明乘的数一定是同一个,接着排序后依次选取,判断一下即可. 题目代码: #include<bits/stdc++.h> using namesp ...
- python3.5opencv3图像文字标注
import cv2 cv2.namedWindow("mark", cv2.WINDOW_AUTOSIZE) image = cv2.imread("../images ...
- 自学Linux Shell2.2-GHOME Terminal仿真器
点击返回 自学Linux命令行与Shell脚本之路 2.2-GHOME Terminal仿真器 GNOME Terminal是GNOME桌面环境的默认终端仿真器.很多发行版,如RHEL.Fedora和 ...
- 【转】如何基于linux进程通信设计方案
前言 linux下的进程通信手段基本上是从Unix平台上的进程通信手段继承而来的.而对Unix发展做出重大贡献的两大主力AT&T的贝尔实验室及BSD(加州大学伯克利分校的伯克利软件发布中心)在 ...
- Nginx入门篇
Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 ...