结合"hello world"探讨gcc编译程序的过程

本博客(http://blog.csdn.net/livelylittlefish)贴出作者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

 

 

结合"hello world"探讨gcc编译程序的过程

 

1. gcc简介

 

gcc/g++GNU工程的CC++编译器。都要用四个步骤中的一个或多个处理输入文件。

·         预处理(preprocessing)

·         编译(compilation)

·         汇编(assembly)

·         连接(linking)

 

源文件后缀名标识源文件的语言,但是对编译器来说,后缀名控制着缺省设定。

gcc命令的一般格式为:gcc [选项] 要编译的文件 [选项] [目标文件]

 

gcc的详细内容,可参考gcc manual

 

2. gcc的输出选项

 

gcc输出选项,-o后指定输出文件名,gcc解释如下。

`-o FILE'

     Place output in file FILE.  This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

     If `-o' is not specified, the default is to put an executable file in `a.out', the object file for `SOURCE.SUFFIX' in `SOURCE.o', its assembler file in `SOURCE.s', a precompiled header file in `SOURCE.SUFFIX.gch', and all preprocessed C source on standard output.

 

    指定输出文件为FILE,该选项不考虑GCC产生什么输出,无论是可执行文件、目标文件、汇编文件还是预处理后的C代码。

    如果没有使用`-o'选项,默认的输出结果是:可执行文件为a.outsource.suffix的目标文件是source.o,汇编文件是source.s,而预处理后的C代码送往标准输出。

 

3. "hello wolrd"的处理过程

 

本文以"hello world"程序,探讨GCC编译程序的过程。

 

hello.c文件内容如下。

#include <stdio.h>

 

int main(int argc, char **argv)

{

    printf("Hello World! via %x/n", printf);

    return 0;

}

 

3.1 预处理

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值