Xcode 3.2.1 GCC CLANG 和 LLVM 揭秘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1551099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 3.2.1 GCC CLANG and LLVM demystification
提问by slf
The readme included with the new Xcode 3.2.1 this week says the following:
本周包含在新 Xcode 3.2.1 中的自述文件如下:
- Static code analysis is fully integrated within the Xcode IDE via the Build and Analyze option under the Build menu or via custom build settings
- GCC 4.2 is the default system compiler for the 10.6 SDK
- The optional LLVM compiler is included using two different front ends - the Clang compiler is a leading-edge parser that offers dramatically improved compile times. For maximum compatibility, the GCC LLVM compiler utilizes the LLVM back-end with the GCC 4.2 parser.
- New optional Clang-LLVM 1.0 compiler uses the much faster Clang front-end parser coupled with the LLVM back-end compiler for fast compiles and fast executable code. Many projects will benefit from this compiler combination, although GCC 4.2 is still the system default. The Clang-LLVM 1.0 compiler will fall back to using LLVM-GCC 4.2 when it encounters C++ code.
- 静态代码分析通过 Build 菜单下的 Build and Analyze 选项或通过自定义构建设置完全集成在 Xcode IDE 中
- GCC 4.2 是 10.6 SDK 的默认系统编译器
- 可选的 LLVM 编译器使用两个不同的前端包括在内 - Clang 编译器是领先的解析器,可显着缩短编译时间。为了获得最大的兼容性,GCC LLVM 编译器使用带有 GCC 4.2 解析器的 LLVM 后端。
- 新的可选 Clang-LLVM 1.0 编译器使用速度更快的 Clang 前端解析器与 LLVM 后端编译器相结合,以实现快速编译和快速可执行代码。许多项目将从这种编译器组合中受益,尽管 GCC 4.2 仍然是系统默认值。Clang-LLVM 1.0 编译器在遇到 C++ 代码时将回退到使用 LLVM-GCC 4.2。
Our company has existing projects that are pure C, Objective-C, and Objective-C++ for desktop and iphone. Can someone summarize at a high-level the differences between LLVM, GCC, CLANG, CLANG-LLVM, WordFoo et. al. and explain what they are and when we should be using each and for what? It would be nice to have links to more a detailed explanation, but I'm really just looking for a high-level overview.
我们公司现有的项目是纯 C、Objective-C 和 Objective-C++ 的桌面和 iphone。有人可以概括总结一下 LLVM、GCC、CLANG、CLANG-LLVM、WordFoo 等之间的差异吗?阿尔。并解释它们是什么以及我们应该何时使用它们以及用于什么目的?有更详细解释的链接会很好,但我真的只是在寻找高级概述。
回答by d0k
In a nutshell:
简而言之:
Compilers are basically split into two parts. One being the front-end that contains the parser and semantic analysis for the programming language. The front-end produces some kind of intermediate representation of your code. Then there's the backend which takes the stuff the front-end produced, optimizes it, and eventually generates assembly code.
编译器基本上分为两部分。一个是包含编程语言解析器和语义分析的前端。前端生成代码的某种中间表示。然后是后端,它接受前端生成的东西,对其进行优化,并最终生成汇编代码。
- GCC: well known compiler, contains both front-ends for various languages and back-ends for many processor architectures
- LLVM: a set of back-ends for various architectures (and other low-level stuff)
- clang: a new front-end for C, Objective-C, and C++; uses the LLVM back-ends. You'll get more readable errors and warnings from your compiler and shorter compile times. You might also encounter incompatibilities or bugs; clang is a very young project.
- LLVM-GCC: GCC's front-end with LLVM's back-end. LLVM's back-end is faster than GCC's.
- GCC:著名的编译器,包含各种语言的前端和许多处理器架构的后端
- LLVM:一组用于各种架构(和其他低级东西)的后端
- clang:C、Objective-C 和 C++ 的新前端;使用 LLVM 后端。您将从编译器中获得更多可读的错误和警告,并缩短编译时间。您可能还会遇到不兼容或错误;clang 是一个非常年轻的项目。
- LLVM-GCC:GCC 的前端与 LLVM 的后端。LLVM 的后端比 GCC 的要快。
clang's (Objective-)C++ support is far from being complete so it calls llvm-gcc when it encounters a C++ source file. It also contains the static analyzer that is now integrated into Xcode. Some people say LLVM's back-end generates better code than GCC's but your mileage may vary. LLVM also supports link-time optimizations (which you can enable in Xcode's project settings). They may produce faster code.
clang 的(Objective-)C++ 支持远未完成,因此它在遇到 C++ 源文件时调用 llvm-gcc。它还包含现在集成到 Xcode 中的静态分析器。有人说 LLVM 的后端生成的代码比 GCC 的更好,但您的里程可能会有所不同。LLVM 还支持链接时优化(您可以在 Xcode 的项目设置中启用)。他们可能会产生更快的代码。
Apple wants to replace GCC with clang in the future because they have a policy against GPLv3 licensed code (GCC 4.2 is the last version that's licensed under GPLv2).
Apple 想在未来用 clang 替换 GCC,因为他们有反对 GPLv3 许可代码的政策(GCC 4.2 是根据 GPLv2 许可的最后一个版本)。