Developing iPhone applications on Linux.

Introduction

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.


Jail Breaking

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.

http://en.wikipedia.org/wiki/Mach_(kernel)

http://en.wikipedia.org/wiki/Darwin_(operating_system)

http://en.wikipedia.org/wiki/Chrooted

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).

Cydia & installer Icons

Cydia & installer Icons

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
cd ~/iphone-2.0-toolchain

./make-toolchain

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

#include

int main(void) {

printf(Hello, iPhone from Linux Eclipse!\n”);

return 0;

}

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

CC=/usr/local/bin/arm-apple-darwin9-gcc

CXX=/usr/local/bin/arm-apple-darwin9-g++

LD=$(CC)

all: helloiphone

helloiphone: helloiphone.o

$(LD) $(LDFLAGS) -o $@ $^

%.o: %.c

$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@

clean:

rm *.o helloiphone

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

ssh root@IPHONE_IP

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.

now type ldid -S helloiphone

& then type the following command

./helloiphone

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.

Conclusion

Have Fun !!!

In the next post we will try to install tool-chain on Windows XP box.

About these ads
    • Tony kuriakose
    • July 7th, 2009
      • aikhan
      • July 7th, 2009

      Yes Tony I think I will have to re-upload it.

      I’ll provide you with the link when I am done

      It will take a while as the file is in my home PC & my home internet connection sucks.

  1. thanks !! very helpful post!

  2. hm, wrong md5

    • Neaftibbani
    • October 14th, 2009

    Hello, it really interesting, thanks

  3. @aikhan
    This is not related to this but to your comment on Malik Siraj Akbar’s blog(gmcmissing.wordpress.com):
    “The next thing they will say that there are weapons of mass destruction in Quetta.

    The only thing I know that there are no talibans in Quetta but there will be thousands once CIA operated drones starts killing innocent people.”

    Sorry I have to reply hear but Siraj has taken a disliking to me since I questioned his support for drone strikes on Quetta. Yes — believe it or not he says Quetta must be droned (please do see the exchange between him and me there.) Of course he goes on to claim ‘ALL Nationalist parties of Baluchistan support drone strikes on Quetta’ (though interestingly he did not name one whwn I asked him — he conveniently removed my comment). Earlier I had taken him to task on his sorry excuse/claim that “sexual harrassment” and “sexual slavery” were one and the same. So of course he has started deleting my comments. Of course calling him Sethi’s bitch (of course I did it politely) did not help ;-)

      • aikhan
      • October 23rd, 2009

      You are talking about Najam Sethi..?

      Yes this guy is weird I think he is some how on a stipend from the forces that seek to break Balochistan away from Pakistan….

      I have seen some of his other blogs posts & I am pretty sure his patriotism is questionable….
      who is he anyway ….? He writes for the Daily Times …?

  4. Hi there.
    Great installation help…thanks, fixed my problem.
    Anyone reading this guys stuff should bookmark it.

  5. You you could change the blog name title Developing iPhone applications on Linux. Asad khan’s Blog to more catching for your subject you write. I enjoyed the blog post all the same.

    • Angel
    • December 13th, 2010

    This is a really awesome post, but how would you get the application on a iPhone? How would it even run on an iPhone? That application just prints out a line of text, would the iPhone just open up a terminal and print that line out?

      • aikhan
      • December 20th, 2010

      No actually you’ll ssh to iphone & connect to its terminal, like you connect to some remote server and then execute the program you have developed. You will have to copy your app file to the application directory to appear on spring board I believe.

      If you’re interested more check out the book iPhone Open Application Development by Jonathan Zdziarski.

      Though I would recommend you if you’re serious to really get a mac & do your development on it.

  6. can i start with iPad ??

    • iphone_newbiew
    • May 22nd, 2012

    Thanks for the excellent article.
    I am just starting out with a linux m/c. How much has changed since 2009? what needs to be done for sdk beyond 3.0 version?

    Thanks

  7. Very rapidly this website will be famous amid all blog people, due to
    it’s good articles

  8. Thanks for the marvelous posting! I certainly enjoyed reading it, you may be a great author.I will remember to bookmark your blog and definitely will come back someday. I want to encourage you to continue your great work, have a nice day!

  9. Highly energetic post, I loved that bit. Will
    there be a part 2?

      • aikhan
      • August 21st, 2014

      Its more than 5 years old post :)
      There won’t be any part 2 LOL

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: