首页 > 其他 > 详细

GCC编译器

时间:2015-03-25 21:08:29      阅读:189      评论:0      收藏:0      [点我收藏+]

编译过程

    预处理器cpp    编译器gcc    汇编器as     链接器linker   

file.c   ------------------> file.i  ------------------>file.s ---------------->file.o ------------------->file.out

file.h                          libc.a

 

gcc选项概述
man gcc                 查看更多选项信息
gcc [options] [filename]
    -x language
    -c                    只对文件进行编译和汇编,不链接
    -S                    只对文件进行编译,不汇编和链接
    -E                    只对文件进行预处理
    -o [file] file2     
    -I library            用来指定所使用的库文件
    -I directory        为include文件搜索指定目录
    -w                     禁止警告信息
    -pedantic            严格要求符合ANSI标准
    -Wall                显示附加的警告信息
    -g                     添加调试信息
    -p                     产生prof所需的信息
    -pg                    产生gpof所使用的信息
    -O(-O1)             对编译出的代码进行优化
    -O2                 进行比-O高一级的优化
    -O3                 产生更高级别的优化
    -v                  
    -m***                根据不同的微处理器进行优化

详解:
    gcc -c test.c                生成.o文件
    gcc -S test.c                生成汇编文件.s
    gcc -E test.c -o test.i     生成.i
    gcc -V 2.6.3 -v              强制执行2.6.3版本
    gcc -m486                     使用对486的相应优化效果

    gcc -Wall -o test test.c

    gcc -g -Wall -o test3_1 test3_1.c
    gcc -ggdb3 -Wall -o test3_1 test3_1.c     -ggdb3使用最高级别的调试信息

    高级gcc选项
    1.管理大型项目(多模块的编译)
        gcc -Wall -c -o test3_1 test3_1.c
        gcc -Wall -c -o test3_2 test3_2.c
        gcc -Wall -c -o test3_3 test3_3.C
        gcc -o test test3_1.o test3_2.o test3_3.o
    2.指定查找路径 (-I -L)
        gcc -Wall -I/usr/include/zw -o test test.c
        gcc -Wall -L/usr/X11R6/lib -Wall -o test test.c -IX11
    3.链接库(-l) l链接的库可以是静态的也可以是共享的。

  gcc -o test test3a.o test3b.o test3.o -lm
        
    4.使用管道(使管道前的输出成为管道后的输入,可以同时调用多个程序) ?
        gcc -pipe -Wall -O3 -o test test.c  
        
Gcc编译流程
    C预处理    (C预处理器cpp)
    Gcc     (gcc)
    汇编     (as)
    文件处理建立静态库    (ar)
    GUN链接    (ld)
    
    辅助:
    库显示    (ldd)

/*************************
此程序设计的性能很低。用于比较优化前后的性能

导致程序低效的原因:
for循环的结束值及步长每次都要重新计算
five变量没有必要每次循环都为它分配值,只要在循环前做一次赋值即可

**************************/

#include <stdio.h>

int main(void)
{
	int counter;
	int ending;
	int temp;
	int five;
	for(counter=0;counter<2*100000000*9/18+5131;counter+=(5-3)/2)
	{
		temp=counter/15302;
		ending=counter;
		five=5;
	}
	printf("five=%d;ending=%d\n;temp=%d",five,ending,temp);
	return 0;
}

 带优化与不带优化的编译差别

//test3_2.c 程序优化
gcc -Wall -o test3_2 test3_2.c
time ./test3_2 					//查看程序运行时间

gcc -Wall -O1 -o test3_2pro test3_2.c
time ./test3_2pro

 

GCC编译器

原文:http://www.cnblogs.com/kwseeker-bolgs/p/4366684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!