How to compile for your iPhone

by Erica Sadun

Here's a quick how-to for people wondering how they can install the iPhone toolchain and try out their own command-line programs.

1. Jailbreak your iPhone and install ssh. You need full access to your iPhone's file system.
2. Download a copy of the binary toolchain and unpack it onto your i386 Macintosh.
3. Copy arm-cc-specs to your home folder as .arm-cc-specs
4. Move the entire build (local-toolchain) into /usr/local/. (I don't recommend breaking it out any further so you keep the entire install together.)
5. Edit .arm-cc-specs to match the location of your toolchain, e.g. /usr/local/local-toolchain/share/
6. Edit your path to include /usr/local/local.toolchain/bin and start a new window so the path matches up.
7. Create a new, standard helloworld.c
8. Attempt to compile it using arm-apple-darwin-cc, which will now be in your path. This will fail.

And now we come to the hard part. You either have to edit your system headers, which Apple made read-only for a reason, or load pre-updated headers, which you'll have to google for. Editing headers basically goes like this: Whenever your compile fails, add || defined(__arm__) to any line that includes if or elif defined (__i386__). Repeat as needed until your hello world compiles. Then, copy your executable to your iPhone and test it there.


2007-07-28 07:35:57
i386 Macintosh? Who talks that way in a hint like this or is a cut and paste article?
2007-07-28 18:34:53
Who talks that way? My guess would be someone who has used XCode, as that is what Apple calls their Intel line under compile options.
2007-07-29 20:26:24
Every site seems to assume you're already knowledgeable about building a cross-compiling toolchain for the iPhone - like you would need these instructions if you were already knowledgeable...

So how about clarifying "jailbreak" please (since it's already changed with iActivator) or at least provide links to what it is - and clarify "copy arm-cc-specs" since there's no such file or directory there (there's 2 files that start with that name) and certainly please clarify the command line directive when building: --with-heavenly= where and what is the heavenly user bundle??

Again all these instructions everywhere including the main dev wiki of all places or even the included INSTALL file are not only incomplete and vague but at places technically incorrect/outdated (ok yes it's always work in progress but you'd think they'd update their docs as regularly as the latest news...)

Of all places, should've done a better job...

M. David Peterson
2007-08-01 00:32:39

Thanks for this! For those of us who have actually learned the basics of computer programming this saves a TON of time and opens a TON of doors in regards to getting applications running on the iPhone.

Thanks again! :D

2007-08-01 14:48:25
First of, my apologies as I didn't mean any disrespect. My mistake, as this is a blog entry and not an article - oops!

But for an entry called "How to compile for your iPhone" to start off with "1. Jailbreak your iPhone and install ssh.." Well it doesn't help those who clicked on the link who don't know what "Jailbreak your iPhone" means.

Yes I can Google, in fact that's how I learned the right way to do it. And yes, I did pay quite a lot, in time. Even the sites that hold your hand with screenshots have mistakes but at least they don't gloss over pertinent info for the sake of a very brief "me too" bulleted list.

It's not correct to edit your system's header files by adding || defined(__arm__) to any line that includes if or elif defined (__i386__) It's preferable to add a separate elif (__arm__) as things may actually be different between i386 and arm as indicated at the iPhone dev wiki and their efforts to provide iPhone headers e.g. the /usr/include/arm header files.

2007-08-08 17:25:11
Heavenly is the name of the decrypted disk image containing the iPhone's file system. Once you've downloaded the firmware from Apple, go to this page: iphone firmware decryption.

Good luck.

2007-08-22 15:16:02
anyway to compile apps on another platform? like say, gentoo? any instructions?