GCC:GNU(Gnu's Not Unix)编译器套装(GNU Compiler Collection,GCC),指一套编程语言编译器,以GPL及LGPL许可证所发行的自由软件,也是GNU项目的关键部分,也是GNU工具链的主要组成部分之一。GCC(特别是其中的C语言编译器)也常被认为是跨平台编译器的事实标准。1985年由理查德·马修·斯托曼开始发展,现在由自由软件基金会负责维护工作。GCC原本用C开发,后来因为LLVM、Clang的崛起,它更快地将开发语言转换为C++。

GCC支持的语言:原名为GNU C语言编译器(GNU C Compiler),因为它原本只能处理C语言。GCC在发布后很快地得到扩展,变得可处理C++。之后也变得可处理Fortran、Pascal、Objective-C、Java、Ada,Go与其他语言。

许多操作系统,包括许多类Unix系统,如Linux及BSD家族都采用GCC作为标准编译器。苹果电脑预装的Mac OS X操作系统也采用这个编译器。

GCC目前由世界各地不同的数个程序员小组维护。它是移植到最多中央处理器架构以及最多操作系统的编译器。由于GCC已成为GNU系统的官方编译器(包括GNU/Linux家族),它也成为编译与创建其他操作系统的主要编译器,包括BSD家族、Mac OS X、NeXTSTEP与BeOS。

GCC通常是跨平台软件的编译器首选。有别于一般局限于特定系统与运行环境的编译器,GCC在所有平台上都使用同一个前端处理程序,产生一样的中介码,因此此中介码在各个其他平台上使用GCC编译,有很大的机会可得到正确无误的输出程序。

GCC支持的主要处理器架构:ARM、x86、x86-64、MIPS、PowerPC等。

GCC结构:GCC的外部接口长得像一个标准的Unix编译器。用户在命令行下键入gcc之程序名,以及一些命令参数,以便决定每个输入文件使用的个别语言编译器,并为输出代码使用适合此硬件平台的汇编语言编译器,并且选择性地运行连接器以制造可执行的程序。每个语言编译器都是独立程序,此程序可处理输入的源代码,并输出汇编语言码。全部的语言编译器都拥有共通的中介架构:一个前端解析匹配此语言的源代码,并产生一抽象语法树,以及一翻译此语法树成为GCC的寄存器转换语言的后端。编译器最优化与静态代码解析技术在此阶段应用于代码上。最后,适用于此硬件架构的汇编语言代码以杰克·戴维森与克里斯·弗雷泽发明的算法产出。

几乎全部的GCC都由C/C++写成,除了Ada前端大部分以Ada写成。

Clang:是一个C、C++、Objective-C和Objective-C++编程语言的编译器前端。它采用了底层虚拟机(LLVM)作为其后端。它的目标是提供一个GNU编译器套装(GCC)的替代品。作者是克里斯·拉特纳(Chris Lattner),在苹果公司的赞助支持下进行开发,而源代码授权是使用类BSD的伊利诺伊大学厄巴纳-香槟分校开源码许可。Clang主要由C++编写。

Clang项目包括Clang前端和Clang静态分析器等。这个软件项目在2005年由苹果电脑发起,是LLVM(Low Level Virtual Machine)编译器工具集的前端(front-end),目的是输出代码对应的抽象语法树(Abstract Syntax Tree, AST),并将代码编译成LLVM Bitcode。接着在后端(back-end)使用LLVM编译成平台相关的机器语言。

Clang本身性能优异,其生成的AST所耗用掉的内存仅仅是GCC的20%左右。2014年1月发行的FreeBSD10.0版将Clang/LLVM作为默认编译器。

Clang性能:测试证明Clang编译Objective-C代码时速度为GCC的3倍,还能针对用户发生的编译错误准确地给出建议。

GCC与Clang区别

GCC特性:除支持C/C++/ Objective-C/Objective-C++语言外,还是支持Java/Ada/Fortran/Go等;当前的Clang的C++支持落后于GCC;支持更多平台;更流行,广泛使用,支持完备。

Clang特性:编译速度快;内存占用小;兼容GCC;设计清晰简单、容易理解,易于扩展增强;基于库的模块化设计,易于IDE集成;出错提示更友好。

Clang采用的license是BSD,而GCC是GPLv3

它们使用的宏不同

(1)、GCC定义的宏包括:

__GNUC__
__GNUC_MINOR__
__GNUC_PATCHLEVEL__
__GNUG__

(2)、Clang除了支持GCC定义的宏之外还定义了:

__clang__
__clang_major__
__clang_minor__
__clang_patchlevel__

Clang vs GCC(GNU Compiler Collection):

Pro's of GCC vs clang:

(1)、GCC supports languages that clang does not aim to, such as Java, Ada, FORTRAN, Go, etc.

(2)、GCC supports more targets than LLVM.

(3)、GCC supports many language extensions, some of which are not implemented by Clang. For instance, in C mode, GCC supports nested functions and has an extension allowing VLAs in structs.

Pro's of clangvs GCC:

(1)、The Clang ASTs and design are intended to be easily understandable by anyone who is familiar with the languages involved and who has a basic understanding of how acompiler works. GCC has a very old codebase which presents a steep learning curve to new developers.

(2)、Clang is designed as an API from its inception, allowing it to be reused by source analysis tools, refactoring, IDEs (etc) as well as for code generation. GCC is built as a monolithic static compiler, which makes it extremely difficult to use as an API and integrate into other tools. Further, its historic design and current policy makes it difficult to decouple the front-end from the rest ofthe compiler.

(3)、Various GCC design decisions make it very difficult to reuse: its build system is difficult to modify, you can't link multiple targets into one binary, you can't link multiple front-ends into one binary, it uses a custom garbage collector, uses global variables extensively, is not reentrant or multi-threadable, etc. Clang has none of these problems.

(4)、Clang does not implicitly simplify code as it parses it like GCC does. Doing so causes many problems for source analysis tools: as one simple example, if you write"x-x" in your source code, the GCC AST will contain "0",with no mention of 'x'. This is extremely bad for a refactoring tool that wants to rename 'x'.

(5)、Clang can serialize its AST out to disk and read it back into another program, which is useful for whole program analysis. GCC does not have this. GCC's PCH mechanism(which is just a dump of the compiler memory image) is related, but is architecturally only able to read the dump back into the exact same executable as the one that produced it (it is not a structured format).

(6)、Clang is much faster and uses far less memory than GCC.

(7)、Clang has been designed from the start to provide extremely clear and concise diagnostics(error and warning messages), and includes support for expressive diagnostics.Modern versions of GCC have made significant advances in this area,incorporating various Clang features such as preserving typedefs in diagnostics and showing macro expansions, but GCC is still catching up.

(8)、GCC is licensed under the GPL license. clang uses a BSD license, which allows it to be embedded in software that is not GPL-licensed.

(9)、Clang inherits a number of features from its use of LLVM as a backend, including support for a bytecode representation for intermediate code, pluggable optimizers, link-time optimization support, Just-In-Time compilation, ability to link in multiple code generators, etc.

(10)、Clang's support for C++ is more compliant than GCC's in many ways.

(11)、Clang supports many language extensions, some of which are not implemented by GCC. For instance, Clang provides attributes for checking thread safety and extended vector types.

以上内容主要整理自: GCC维基百科  、  Clang维基百科 、 clang.llvm.org

编译器GCC与Clang的异同相关推荐

  1. gcc、clang、make、cmake、makefile、CMakeLists.txt概念学习

    说明 编译器是翻译代码为计算机语言的一个工具,我们平时写的代码如果想在某个特定的计算机上执行(计算机的cpu构架不同),就需要编译器来对代码进行编译汇编链接,而汇编和链接的过程对于每个不同的平台上过程 ...

  2. GCC和Clang的两个值得了解的编译器开关

    GCC和Clang的两个值得了解的编译器开关,在系统编程中非常有用. -fno-strict-aliasing 禁止依赖于严格别名规则的优化.严格别名规则指的是两个不相关类型的指针解引用不会相互影响, ...

  3. Linux编译器GCC的使用

    嵌入式Linux编译器GCC的使用 1.GCC概述 作为自由软件的旗舰项目,Richard Stallman在十多年前刚开始写作GCC的时候,还只是仅仅把它当作一个C程序语言的编译器,GCC的意思也只 ...

  4. MinGW-w64安装教程——著名C/C++编译器GCC的Windows版本

    基本操作就是将下面下载的任意版本解压到你想安装的目录而后将bin 添加到环境变量即可 https://download.csdn.net/download/weixin_32759777/850205 ...

  5. Linux 之 编译器 gcc/g++参数详解

    2016年12月9日16:48:53 ----------------------------- 内容目录: [介绍]  gcc and g++分别是gnu的c & c++编译器 gcc/g+ ...

  6. 【Linux】三、Linux 环境基础及开发工具使用(上篇)|开发工具|编辑器-vim使用|sudo提升权限问题|编译器 - gcc/g++使用|项目自动化构建工构建工具-make/Makefile

    目录 一.开发工具 二.Linux编辑器 - vim使用 2.1 vim 的基本概念 2.2 vim的基本操作 2.3 vim正常模式命令集 2.4 vim末行模式命令集 2.5 简单vim配置 2. ...

  7. Day 3 Linux(目录篇 、文件操作篇 、压缩解压相关命令, 编辑器vi 、编译器gcc 、调试器gdb、 makefile工程管理器初学)

    一.目录篇: 1.文件处理命令:cp 英文原意:copy 语法:cp -rp[源文件或目录][目的目录] 源文件可以同时是多个,即同时复制到多个文件 -r 复制目录 -p保留文件属性,比如文件创建时间 ...

  8. C/C++编译器gcc的windows版本MinGW-w64安装教程

    一.什么是 MinGW-w64 ? MinGW 的全称是:Minimalist GNU on Windows .它实际上是将经典的开源 C语言 编译器 GCC 移植到了 Windows 平台下,并且包 ...

  9. Redhat linux 安装 gcc编译器,Gcc源码包,rpm包安装方法!

    点评:分两种情况: 先看这篇转过来的文章,俺老孙懒得写了. Linux软件安装通用思路 在Linux系统中,软件安装程序比较纷繁复杂,不过最常见的有两种: 1)一种是软件的源代码,您需要自己动手编译它 ...

最新文章

  1. JAVA好书之《深入理解Java虚拟机》
  2. Mac 配置支持 opengl 的 opencv 4.2
  3. a good approach to make demonstrations at the baidu netdisk
  4. 数据结构与算法 | 归并排序
  5. groovy grails_在Grails战争中添加一个“精简”的Groovy Web控制台
  6. MySql 从查询结果中更新数据
  7. 编辑电线标注及图纸上从主电源线上引出多条支路时如何进行线号的编写?
  8. 在vmware server中部署linux redhat 5.4 ORACLE RAC11g +ASM
  9. iOS媒体视频播放器应用源码
  10. 谈谈时间序列的平稳性
  11. iOS 基础入门--Bull' Eye 小游戏 
  12. 天气预报接口使用及示例
  13. 机器学习性能改善备忘单:32个帮你做出更好预测模型的技巧和窍门
  14. 数十万互联网从业者的共同关注!
  15. redis 优惠券秒杀逐步优化
  16. 回归常态啦 2020.12.08日记
  17. 百度竞价点击价格怎么算
  18. 消防审批时限减了一半
  19. php拆分excel,PHP如何切割excel大文件(附完整代码)
  20. 德鲁克:这4种创新方式,使变化成为机会

热门文章

  1. Postgresql:INSERT INTO ON CONSTRAINT pk_key_id do nothing
  2. elasticsearch 索引 red 状态恢复 green
  3. 5行Python代码实现图像分割
  4. (Python)石头剪刀布游戏
  5. linux下Qt调用C++库文件(.so)程序实现
  6. c++创建包含opencv的dll供C,C#调用
  7. python迭代计算_如何在Python中迭代坐标列表并计算它们之间的距离
  8. Angular的ChangeDetectorRef.detectChanges()实现angularJS的$apply()方法,强制刷新数据渲染
  9. webstorm打开新项目提示设置、是否在新窗口打开提示
  10. 关于 智能指针 的线程安全问题