In latest iOS SDK, Apple provides three compiler options: GCC, LLVM with Clang and LLVM-GCC. I understand more or less what these 3 mean, what LLVM and Clang are, and so on. What I don't know is what this means in practice for iPhone developers. Which of these should I use at this point, as of January 2011? Is LLVM mature enough that I can use it safely without stumbling on bugs in it too often? Does switching to LLVM have any other disadvantages? If it does, then does the speed advantage outweigh them? Are there any other reasons to switch except speed?
5 回答
更新:因为人们仍在寻找这个答案,我觉得我应该提供一个合适的更新。到目前为止,我希望 Clang 绝对是编程时要走的路,Clang 是新版本 Xcode 中的默认编译器,并支持 ARC 和新的和即将推出的语言结构(数组和字典下标、文字等) . 几乎完全没有理由再使用 GCC 进行编译,对于使用 ARC 和新特性的代码库,使用普通 GCC 不再相关或不可能(LLVM-GCC 可能支持这些特性,但由于 Clang 已经完全稳定的)。
到目前为止(LLVM-2.0 包含在 Xcode 4.0 测试版中),LLVM 已经足够成熟,可以用于生产代码。它的编译速度比 GCC 快一点,生成的代码也更快,所以尽可能使用它(几乎,如果有更好的东西,尽量避免使用 GCC)。标准的 Xcode 3.2.5 安装包含 LLVM-1.6(不是最新版本),因此我建议您运行一些速度测试以查看 GCC 和 LLVM 之间是否存在明显差异,或者从源代码编译 Clang 并获取最新版本。
本质上,不再需要 GCC,LLVM + Clang 就足够了。
好的,我认为下面的答案都不能说明整个故事,所以这是我对我的问题的回答:
LLVM 编译代码的速度比 GCC 快,可能创建的代码运行速度更快,而且 Clang 前端提供的错误消息比 GCC 更准确——因此肯定有切换的理由;
也就是说,最新稳定的 Xcode (LLVM 1.6) 提供的版本还不是 100% 稳定,如果你不走运,可能会遇到一些小错误。因此,如果您想安全起见,您应该从源代码编译最新的 LLVM (2.0),或者在接下来的几个月里坚持使用 GCC;
再过几个月,可能苹果发布 Xcode 4 时,LLVM 2.0 就会成为 Xcode 默认自带的版本,届时我们应该都可以安全地切换到它了。
感谢所有回复的人,如果我有错误,请随时纠正我。
I have an app that seems to crash on launch on the original iPhone running iOS 3.1.3 when compiled with LLVM 2.0, but runs just fine with LLVM-GCC. I support back to iOS 3.1 so this is fatal. Not sure if there's an interaction between LLVM 2.0 and some specific code I have, but it seems best to avoid LLVM if you need to support iOS 3.x unless you can test thoroughly on legacy devices.
Update: It seems that the issue is with the device hardware rather than iOS version. 1st and 2nd generation iOS devices seems to be affected: Original iPhone, iPhone 3G, and 1st and 2nd gen iPod Touch. I believe this means it's limited to ARMv6 architectures.
Also, running a debug build via Xcode's debugger works fine, while release builds installed via iTunes do not. So it might be an interaction between CPU architecture and optimization level with LLVM 2.0.
But in any case, avoid for now ;)
切换到 Clang 的另一个主要原因是更准确(列和行号范围)和可读的错误消息。
在最新的 WWDC10 期间,他们特别鼓励开发人员使用更新的 LLVM 编译器。我忘记了他们详细介绍的确切内容——“Xcode 中的新内容”之一。基本上他们建议尽可能使用 LLVM-2.0,否则使用 LLVM-GCC 并完全避免单独使用 GCC。
如果您是注册的 iOS 开发者,您可以在 http://developer.apple.com/videos/wwdc/2010/免费观看大部分课程