LLVM vs. GCC for iOS Development

In the latest iOS SDK, Apple provides three compiler options: GCC, LLVM with Clang, and LLVM-GCC. I understand more or less what these 3 mean, LLVM and Clang, and so on. What I don’t know is what in practice means for iPhone developers. Which one should I use at the moment, as of January 2011? Is LLVM mature enough so that I can use it safely without encountering errors too often? Do other LLVMs have any other disadvantages? If so, is the speed advantage superior to them? Are there other reasons for switching besides speed?

+46
compiler-construction objective-c iphone clang llvm
Jan 03 '11 at 23:23
source share
5 answers

Update: Since people still find this answer, I feel that I should provide a suitable update. For now, I hope that it is clear that Clang is absolutely a way of programming when programming, when Clang is the default compiler in new versions of Xcode and supports ARC, as well as new and upcoming language constructs (signatures, literals, etc.). ), There is almost no reason to compile with GCC, and for codebases using ARC and new functions, using a simple GCC is no longer relevant or possible (LLVM-GCC can support these functions, but now it does not give advantages over Clang, since Clang is fully stable).




To date (with LLVM-2.0 included in the beta version of Xcode 4.0), LLVM is mature enough for use in production code. It compiles a bit faster than GCC, and produces faster code, so use it whenever you can (pretty much try to avoid GCC if something is better available). The standard installation of Xcode 3.2.5 contains LLVM-1.6 (not the latest), so I would recommend either running some speed tests to see if there is a noticeable difference between GCC and LLVM, or compiling Clang from the source and getting the latest version.

Essentially, there is no longer a need for GCC, LLVM + Clang is more than enough.

+37
Jan 04 2018-11-11T00:
source share

Well, I think that none of the answers below tell the whole story, so here I take the answer to my question:

  • LLVM compiles code faster than GCC, can create code that works faster, and the Clang interface provides more accurate error messages than GCC, so there are certain reasons for switching;

  • that the version with the latest stable Xcode (LLVM 1.6) is not 100% stable yet, you may encounter some minor bugs if you're out of luck. Therefore, if you want to be safe, you must either compile the latest LLVM (2.0) from the source, or stick to GCC for the next few months;

  • in a few months, probably when Apple releases Xcode 4, LLVM 2.0 will be the version that comes with Xcode by default, and then we should all be able to safely switch to it.

Thanks to everyone who answered, do not hesitate to correct me if I have something wrong.

+18
Jan 07 '11 at 18:08
source share

I have an application that seems to crash when starting on the original iPhone running iOS 3.1.3 when compiling with LLVM 2.0, but works fine with LLVM-GCC. I support iOS 3.1, so it is fatal. Not sure if there is an interaction between LLVM 2.0 and some specific code, but it's better to avoid LLVM if you need to support iOS 3.x if you can't fully test legacy devices.




Update: it seems that the problem is with the hardware of the device, and not with the version of iOS. It seems that the first and second generation iOS devices are affected: the original iPhone, iPhone 3G and 1st iPod Touch iPod. I believe this means that it is limited by the ARMv6 architecture.

In addition, performing debug builds through the Xcode debugger works fine, and release builds installed through iTunes do not work. Thus, it may be the interaction between the processor architecture and the optimization level with LLVM 2.0.

But in any case, avoid it for now;)

+9
Apr 03 2018-11-11T00:
source share

Another important reason to upgrade to Clang is the more accurate (ranges of column and row numbers) and readable error messages.

+4
Jan 04 2018-11-11T00:
source share

During the latest WWDC10, they forced developers to use the more advanced LLVM compiler. I forget the exact treatise they described in detail - one of the "new in Xcode." They mainly suggest using LLVM-2.0 whenever possible, otherwise LLVM-GCC and completely avoiding GCC.

If you are a registered iOS developer, you can view most of the sessions at http://developer.apple.com/videos/wwdc/2010/

+3
Jan 03 2018-11-11T00:
source share



All Articles