iPhone app development with Linux
October 4th, 2009 | by richfreedman |My employer, Chariot Solutions, held an in-house, week-long iPhone development course, taught by the folks at Big Nerd Ranch.
The course was great, we all learned a lot, and several of our folks are working on some apps, including one that they announced recently at JBoss World.
80% or more of our consultants have MacBook Pros, however, I opted for a Dell with Ubuntu when I joined Chariot about a year and a half ago.
I borrowed a MacBook for the course (thanks, Ken!), but have been feeling a bit left out since then, as the official Apple development tools (XCode and Interface Builder) only run on OS X.
I had previously whined about the fact that the official toolchain uses GCC under the covers, and that therefore, someone who knows GCC well (as in not me) ought to be able to get something working on Linux. Since then, I’ve seen a few pages on the web with instructions for getting arm-apple-darwin9-gcc working on Linux, but none seemed to have complete instructions on how to get the development environment working.
Well, yesterday, I decided to look harder, and found a site that explains setup of an iPhone development environment on Linux in detail.
With the help of the instructions there, I was able to get the toolchain working under Linux, and with some information gleaned from other websites as well, was able to compile an iPhone app, install it on my phone, and run it. I can stop whining now:-)
So, I’m putting all of the information that I have about this process here, in one place, where I can find it again later – if you have read this far, then I hope it helps you too.
What you need:
- A computer running Linux
- A Jailbroken iPhone (see my previous blog post for instructions)
- A Wifi network to enable your computer to communicate with your iPhone
- A copy of the phone’s firmware – since you just jailbroke your phone, you have a copy of this – it’s the .ipsw file
- The IPhone 3.0 SDK (see http://developer.apple.com/iphone/)
The steps:
- Make sure that the Cydia package manager is installed on your iPhone – if you followed the instructions linked above, it should have been installed as part of the jailbreaking process.
- Use Cydia to install OpenSSH – this installs an SSH Daemon on your phone, so that you can ssh into the phone from your computer. Your makefiles will include ssh and scp commands to get the app to your phone and install it properly. Before moving on to the next step, make sure that you can get OpenSSH running, and can successfully ssh into your phone as root, and get a shell prompt. If you need help with this, look here.
- Use Cydia to install Apt. Sometimes things are just easier from the command-line.
- Use Apt (or Cydia) to install the “ldid” package. Some makefiles that you will encounter will use this to pseudo-sign the app directly on the phone.
- Follow the instructions at http://code.google.com/p/iphonedevonlinux/wiki/Installation to install the toolchain, including installation of the packages listed there.
- Follow the instructions to download and build the HelloToolchain application. Note: make sure that your phone and computer are both connected to the same wifi network, that the SSH daemon is running on your phone, and that you know your phone’s IP address. To make things easier on myself, I set up my wifi router to recognize the iPhone’s mac address, and to always give it the same IP address. Now, I can use a shell script to invoke make with the proper address, and I don’t have to check the phone’s address each time.
Once that simple app builds, installs, and runs, you are almost in business. The major issue is that HelloToolchain, being a simple test app, doesn’t show you how to structure things for a “real” application. And if you’re not a Makefile geek, it may not even be obvious how to build an app that consists of more than one source file. So, go to http://code.google.com/p/apiexplorer/ and download the iPhone API Explorer project. It demos just about every user interface object, and has a really well-thought-out Makefile (be sure to use Makefile.linux) that shows how to build a complex project.
If you have gotten this far, you are probably tired by now of typing in the password for your phone three or four times for each build.
To set up public key authentication for your phone:
- ssh into your phone, use apt to install vim if necessary, and then use it to edit /etc/ssh/sshd_config
- uncomment the line: PubkeyAuthentication yes
- use the ssh-copy-id script to copy your public key to the phone.
That should do it. Happy iPhone programming!

13 Responses to “iPhone app development with Linux”
By Paul on Oct 5, 2009 | Reply
Great article! Thanks for collecting together all this handy info. Much appreciated!
By Raja on Oct 9, 2009 | Reply
does this setup work for ipod touch?
By richfreedman on Oct 9, 2009 | Reply
I don’t see any reason why it wouldn’t work on the touch – as far as I know, it’s the same OS. But I don’t have a touch, so I can’t verify it. If you get it working, let me know!
By iphone application development on Oct 14, 2009 | Reply
nice article and site for information iphone development.
By df on Nov 2, 2009 | Reply
Indeed. Thanks very much for collecting this info in one handy spot!
By Greg on Nov 12, 2009 | Reply
Very detailed tutorial. How does one get iphone sdk 3.0? …couldn’t find it on the developer.apple.com site. Can I still use the 3.1.2 or 3.2.1 sdk’s? That is all apple is letting people download now. I have os 3.0 on my iphone original… running ubuntu, no mac.
By Brian on Dec 13, 2009 | Reply
Thanks for linking to this script – I managed to build the toolchain with very little difficulty. However, I am having linker errors when trying to build the test apps:
brian@vader:~/iphone/toolchain/apps/HelloToolchain$ make deploy
arm-apple-darwin9-gcc -c src/HelloToolchain.m -o HelloToolchain.o
arm-apple-darwin9-gcc -lobjc -bind_at_load -framework Foundation -framework CoreFoundation -framework UIKit -w -o HelloToolchain HelloToolchain.o
ld: library not found for -lobjc
collect2: ld returned 1 exit status
make: *** [HelloToolchain] Error 1
How can I get past this error? Where is this library located?
Thanks!
By richfreedman on Dec 16, 2009 | Reply
@Brian,
Not sure what your issue is, but in my toolchain, I find the following:
toolchain/sys/usr/lib/libobjc.A.dylib
toolchain/sys/usr/lib/libobjc.dylib
By Brian on Dec 18, 2009 | Reply
Hi Rich,
What version did you build? I built the toolchain using the latest version of the Apple SDK and 3.1.2 firmware for the 3G.
Apparently on firmware past 3.1 Apple has put all the libraries in a single cache file instead of in usr/lib.
Brian
By richfreedman on Dec 18, 2009 | Reply
3.0
I’m geussing that’s your problem.
Since I don’t have a Mac (which is why I’m doing this in the first place), I haven’t been able to upgrade my jailbroken phone past 3.0
By Brian on Dec 18, 2009 | Reply
OK, finally some success!
I extracted the usr/lib and System/Library/Frameworks folders from the Apple SDK for 3.1.2 and used them to replace the ones created by the script. Now HelloToolchain builds, deploys, and runs on the iPhone.
I’ve been trying to get an SDK up and running on Linux for at least a month now, and finally it works. Thanks for posting the link to the script – very much appreciated!
By Jack_chen on Mar 6, 2010 | Reply
Hi rich,
When I ldid my HelloToolchain on my JB ipod touch 2,I get following
error message:
util/ldid.cpp(249):_assert(0:Swap(mach_header_->magic)==MH_MAGIC)
I don’t know what lead to this error. Could you help me? Thanks.
By richfreedman on Mar 6, 2010 | Reply
I’m not familiar enough with the internals of the toolchain to be able to really diagnose this.
However, it sounds like you may not have the version of the SDK that your version of the toolchain expects.