As you probably know the Moodstocks SDK core library is written in C and thus is cross-compiled for the target platforms – iOS and Android so far.
Until the latest release (v3.4) we used the GCC 4.2 front-end compiler for the iOS build. We then decided to switch to Clang for several reasons and benefits I will talk about in this post.
The LLVM Project
Clang is a C/C++/Objective-C compiler front-end that is part of the LLVM Project. It’s a very handy compiler to work with because it’s fast – expect faster compile times, and provides a great user experience – via so-called “expressive” error diagnostics.
On my side I was lucky enough to attend Chris Lattner‘s talk at FOSDEM 2011 - Chris is the creator of the LLVM project, and if you want to get a recap in terms of features and benchmarks around LLVM you should definitely browse his slides which are available online.
Xcode default compiler
Apple, which is one of the main company involved within the LLVM project, has now fully switched on it for iOS development: if you grab the latest version of Xcode (4.3.3 at the time of writing) the default and official compiler for iOS is now LLVM. Indeed Apple started migrating from GCC to LLVM as of Xcode 4.1.
That is the main reason why we decided to switch too. But not the only one (see below).
Switching to Clang
When it comes to cross-compiling a C library for the iOS platform, you need to use the proper tools – compiler, linker, archiver, etc, right from the iOS SDK toolchain.
For that purpose Xcode comes with a handy command-line tool called xcrun. With it you can easily obtain e.g. the path of the right version of Clang or even directly execute a command:
With it you can definitely simplify your Makefile or build scripts. For example xcrun is used by the VLC project for its iOS port: