Jay Freeman (saurik) has made some very handy binaries containing the approprite header files for the ‘open’ toolchain for iPhoneOS. These header files complement the GNU Complier Collection (GCC) and the GNU Debugger (GDB) to provide for a complete functioning toolchain right on your device. Here’s how to easily install the whole thing in just a few minutes.
Previously, getting the needed headers proved to be the hardest part to getting a working open toolchain for iPhoneOS for many people. And it isn’t exactly making it easier when some people use OS X, some Linux, and some Windows, in many different flavors. However, since most developers that want to (compile) code for iPhoneOS have an iPhone or iPod Touch anyway, we have a highly uniform platform for setting up a build environment with just a couple of actions. Moreover, the compiled code needs to be on the device to run anyway, so compiling on the device saves us from having to move files onto the device. This also goes for testing, as the Simulator in Apple’s iPhone SDK doesn’t really have the complete functionality of the real device: it misses some of the most interesting things such as multi-touch, accelerometer, camera, microphone. Last but not least, I like the idea of not being dependent on any other device. Wasn’t that the whole point of mobile computing anyway? (On a side note, suggested opening line for chicks that dig geeks: “Are you happy to see me, or is that a GCC in your pocket?”)
So what do we need / presume:
- an iPhone or iPhone Touch that is jailbroken; so, unfortunately, no 2nd Gen. iPod Touch (yet; but keep an eye out for redsn0w…);
- with access to internet (EDGE / GPRS disrecommended, because of the huge size of the files that need to be downloaded);
- you need to enter commands, so you need to have MobileTerminal installed and/or (recommended, for easy copy & paste) you can of course ssh into your device from e.g. Terminal (OS X), PuTTY (Windows). In the latter case, you need to have OpenSSH installed, of course.
The GCC and GDB packages can easily be installed directly from Cydia (make sure you select role: developer, so they will be visible). On the other hand, since we’re going to be using the command line in a couple of minutes anyway, in this case it’s probably easier to install GCC and GDB manually (and, optionally but recommended, Git) using the command apt-get (since Cydia is basically a GUI front-end to APT).
SSH into your device, using e.g. Terminal (OS X, Linux) or WinSCP + PuTTY (Windows):
ssh root@ipadressofyourdevice
Replace “ipadressofyourdevice” with the IP adress of your device, of course (look it up in Settings.app > Wi-Fi, press arrow on current connected network; and make sure your device is connected to the same wireless network as your pc). You will be asked for your password (the default password is “alpine” nowadays, and you are advised to change it first time you can, using the command “passwd”).
Just to be sure, check the remaining storage space:
df -h
These packages take over 40 mb on download and over a 100 mb after installing them, so you need to have enough remaining free storage space. Later on we’re gonna need even more for the headers, and some code, of course. The file folders will get symlinked to the user disk partition (/dev/disk0s2) btw, so don’t worry about the limited size / free space on the system disk partition (/dev/disk0s1).
Next we update the packages lists:
apt-get update
Now we can install GCC and GDB (and get wget at the same time, because we will need it in a moment):
apt-get install iphone-gcc gdb wget
(Note: apt-get uses the package name, and automatically selects the latest version; i.e. excluding the version number, .deb extension that’s in the filename of the associated packages: e.g. iphone-gcc currently pulls in iphone-gcc_4.2-20080604-1-8_iphoneos-arm.deb as that is the most recent version.)
The slightly more difficult part is how to get the needed header files onto the device. First we are going to pull the packages onto the device. I recommend downloading them to /tmp so they aren’t on the system ‘disk’ and get deleted on next reboot, ensuring they don’t unnessecarily take up valuable storage space.
Do (either on the iPhone in Terminal, or ssh-ed into the device):
cd /tmp
wget http://apt.saurik.com/debs/iphoneos-sys_20081001-1-1_iphoneos-arm.deb
wget http://apt.saurik.com/debs/iphoneos-api_20081001-1-1_iphoneos-arm.deb
wget http://apt.saurik.com/debs/iphoneos-sdk_20081001-1-1_iphoneos-arm.deb
Next we’re going to install them. First we will install some other small packages, to make sure we don’t get errors about missing dependencies:
apt-get install bootstrap-cmds ldid make
Then we do (note that the order is important; thus we don’t use “dpkg -i *.deb”):
dpkg -i iphoneos-sys_20081001-1-1_iphoneos-arm.deb
dpkg -i iphoneos-api_20081001-1-1_iphoneos-arm.deb
dpkg -i iphoneos-sdk_20081001-1-1_iphoneos-arm.deb
The headers end up in /usr/include. The paths in your makefiles should reflect this, of course.
To set up a tiny but crucial symlink for C++, also do:
apt-get install libstdc++
For an even fuller / more powerful set of headers, you may also want to get (err, git) an additional set. Since this is on saurik’s Git repository, we’ll have to use git tot get it (git it?). Git can also be installed on the device using Cydia, but again, we’re already on the command line anyway, so we just do it here):
apt-get install git
Then we can download a copy of the most recent version:
git clone git://git.saurik.com/iphone-api.git
This set also includes the all-important GraphicsServices.h header, which is needed for compiling some audio/video stuff, like support for TV-output (for more on that, see e.g. Erica’s great writeup ‘Hidden SDK features transform iPhone into TV gaming device‘ and the follow-ups on that post). This also seems to be useful for GSEvent stuff, since Jay ripped apart what exactly is in there by correlating various assembly dumps.
4 Comments »
RSS feed for comments on this post. TrackBack URL.

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=15ae9466-fe08-4ba0-a566-7e6eccffb4af)