Using GNU gcc to Create and Run a Program on Jailbroken iPad

I had been using DOSpad for any non-APL C/c++ programming, but discovered gcc can be run natively on the iPad.  It turns out Python and even X11 can be built to run locally on the iPad.  For those new to jailbreaking iPad's, here is a photo-essay on how to run a C program native on the iPad.  (Note: I only tested this on my old iPad gen-1, running iOS 5.1.1).

First, jailbreak your iPad, and then, using Cydia, download the GNU C Compiler, from Jay Freeman's (aka Saurik's) repository.  These software repositories (or "repos") are how one gets and loads Debian package files (.deb files) onto the opened-up (jailbroken) iPad.  A .deb file is like a .apk file (for those with Android package development experience). 

To start, press Cydia icon from the Springboard (main UI screen) on iPad, and use search (magnify-glass at screen-bottom icon set) for "gcc", the GNU gcc C-language compiler.   You should also make sure you have the "MobileTerminal" packege installed, so you can bring up a command line screen, where you can enter unix-style shell commands.  (The icon that says "Terminal", beside the Cydia icon).  Jailbreaking should install Cydia, but you may need to add other "repos" (software repositories) to your search-list.  To do this, press "Source" at screen bottom when in Cydia, then press "Edit" in top right-top screen corner, then press "Add" in left-top screen corner.  Enter the URL of the repo in the pop-up box, and press "Done" button, top-screen right side.  As the source loads, it should report a bunch of gpg keys being verified, as per the image to the right of this text here.

Steps:  1) Use Cydia to load package "GNU gcc" from Jay Freeman's repo.

2) Use iFile (from BYA repo) or good old vi/vim to code up a "Hello World" program.  You might have to locate and install vim if you want to find that fine old workhorse.

3) Using Terminal, try to compile your "hello.c" program.  (Watch it fail!)

4) Switch from default jailbreak userid "mobile" to "root", using su.

5) Try to compile it again.  (Watch it get *killed* by the iPad O/S... !)

6) Use the "ldid -S <full path name of your new executable>" to remove Apple's security restrictions, which kill any process not known to iOS. Once security restrictions removed from "Hello", you should be able to enter "./Hello", and the executable should run.  Remember that "ldid -S" needs to be followed by the full pathname of the runnable file, in this case: "/var/mobile/dev/Hello".

7) Get Python 2.7, from Cydia Repo "http://cydia.radare.org/".  You can also pickup a version of libgcc from this site as well.  Just install the cydia.radare.org  repository, and select package Python under "Scripting".  This installs Python 2.7.3 on the iPad, and it appears to work well.  So far, I have been unable to get "numpy" to import, however.

The screenshots below show examples. Hope this helps jailbreaking newbies (like me!).  Once you can run gcc, then a range of applications can be built from source.  Some folks compile Python from source, and one fellow has even built a full X11 environment, running FVWM, on his iPhone, a few years back.  

Standard Caveat:  All this activity is experimental, unsupported, and at your own risk, of course. 

Main UI Screen on iPad, Showing Cydia icon. Touch it!

Search for "gcc". You should see the "GNU C Compile" from repo "apt.saurik.com"

Start "Terminal", and use vi or vim to create "hello.c" test program.

First Attempt at Compile Results in Error-Spew.

Use "su" and become root. Program compiles OK, but "Killed: 9" happens when run.

Success! Use "ldid -S <full pathname of file>" to remove Apple restrictions on the "Hello" program. It can then be run.