As we all know that Apple has limited the native application development of iPhone/Cocoa touch to only the MAC OS X & its IDE Xcode, which consequently leave out a huge number of developers out of the thrill. In this tutorial/article we will try to explore how we can use our beloved Linux machine to develop applications for iPhone/Cocoa touch platform.
We will follow a step by step tutorial to install tool-chain for the iPhone/Cocoa Touch and in the end I will also provide elaboration on how to use our very own Eclipse IDE for code editing features for objective C.
Basic Linux acquaintance and a know how of C language is a pre-requisite.
You will be needing an iPhone, a Linux machine, a wifi connection & a little patience to get it done but I can guarantee you once you have done it you would feel like King Arthur, assuming he always felt good.
I will be using Ubuntu 9.04 Jaunty for the sake of our example.
At its core MAC OS X is based on Darwin which integrates a couple of fascinating technologies, most importantly XNU kernel a Mach 3.0 based microkernel and operating-system services based on 4.4BSD (Berkeley Software Distribution). Darwin forms the core set of components upon which Mac OS X and iPhone OS are based.
Being basically unix in nature Apple employed a popular UNIX technique known as “chroot” to restrict the access of processes to an isolated subset of the file system.
Wikipedia links for the above jargon if you are interested are highlighted below, as I would not go into the irrelevant lengthy details but will give you pointers where the need arises.
The first thing you will need to do is to jail break your iPhone. Jail breaking your iPhone wont break your iPhone it will just set your phone free from the restrictions Apple has applied on it, let your phone breahthe in some fresh air. There are a lot of tutorials and softwares available to do this so I wont waste my time on this too, just google it and you will be on the right grounds for sure.
You can even search in youtube and will find video tutorials on how to break the chains of your phone.
QuickPwn, XPwn, Pwnage, and WinPwn; are just a few keywords to make your life a little easier & a little better.
Don’t scroll down if you haven’t Jail broken your iPhone yet. If you are having trouble jail breaking your iPhone just drop me a line below in comments I would be eager to help you out.
Post Jail Break
There are a few softwares we need to install on the iPhone to get our work done. Depending upon the method/software used you will have an installer or a Cydia icon on your springboard(that is the desktop of your iPhone if in case you are wondering what SpringBoard is).
Search and download the following softwares from either cydia or installer from your iPhone.
OpenSSH secure remote shell client and server(openssh) :enables you to transfer your programs to the iPhone and log in to execute commands on the device
The Linker Identity Editor(ldid): sign your code with a bogus key to make the iPhone run it & the Respring(respring) utility to restart the dashboard.
You can use the keywords in the brackets for search.
Once you have installed ssh open terminal app(Goto Applications on the top right corner of your screen → Accessories → Terminal) & type ssh root@[ip address of iphone], terminal will prompt you to enter roots password type alpine which is the default password for the root. Now type passwd and hit enter to change the default password and secure your iPhone. Do the same procedure for the username mobile which also have the default password alpine.
Note you can see the ip address for your iphone using the Settings application on your iphone and going to WiFi.
Installing the tool-chain
Tool-chain can be installed in two ways, one way which we will discuss further is by downloading the source and compiling the source of the tool-chain and if you don’t want to get into the hassle I will provide my pre-compiled version of tool chain so that you can use it off shelf.
Note tool chain refers to compilers, assemblers, linkers, and other tools that work together to build an executable file for a particular platform; if in case you are wondering what tool chain is.
Installing tool-chain from the source
One advantage you will get from downloading and installing from the source is that you will get the latest build for the tool-chain available.
The iPhone tool chain used by Apple for its iPhone SDK is actually based on the open source GCC — the same tool chain used in Linux, Unix & its variants & which off course is open source.
Because of its open source origins, the base source code for the iPhone SDK is available to anyone under GPL.
The following software’s are necessary to build tool chain on Linux: bison, flex, build-essentials, and autoconf packages. You can use the following command to download and install the programs from the repositories.
The process to download and compile tool chain from the source is explained on the web page http://code.google.com/p/iphone-dev/wiki/Building, If you have any problems or errors while following steps read the comments below and if it still doesn’t suffice leave me a comment I will try to help if possible.
Get a copy of the iPhone root file system, make sure your iPhone and linux box both are connected to the same WiFi network, go to networks double click on the iphone device provide user-name and passwords for authentication and then download these two directories /System/Library/Frameworks/ and /user/lib to your /usr/local directory.
Download the tool chain code from the link
extract the .tar file with any file archiving utility of your choice and then run the following command
It will take a while and a lot of text would whiz by your screen and after a while if all went right you would get your prompt back.
Congratulations! you have installed your tool-chain for iPhone on Linux.
Now open a text editor or any IDE e.g eclipse or netbeans whatever you like
type the following code
save the file as helloiphone.c
Now create a new file save it as makefile & place it the same directory as for the previous file.
Type the following content into it
Please note the spaces above should be tabs for the make file to work you cant just insert spaces , you will have to use tabs to make it work.
Go to the directory where you have these files from the command prompt run the makefile. Type the following command
scp helloiphone root@IPHONE_IP:~/
now type this command to log into the iphone. Where IPHONE_IP is the ip address of your iPhone
iPhone executable loader expects all executables to be signed. We use the ldid command from the Linker Identity Editor utility we installed with Cydia earlier. The ldid command produces a bogus executable signature to fool the executable loader.
ldid -S helloiphone
& then type the following command
TaDa! Our simple C program runs on the iPhone now :).
You can use your Eclipse IDE for Objective C syntax highlighting too just download your respective files from http://gstaff.org/colorEditor/download.html & then paste just paste the .jar file in the plug-ins folder of your eclipse installation directory.
You can basically use exactly the same procedure to compile & execute objective C files.
Have Fun !!!
In the next post we will try to install tool-chain on Windows XP box.
The article was first published on here on 1st June 2009, most of the things have changed and aforementioned method might not work now.