Compile c applications on Iphone 4 using gcc

Hello folks, today we'll see how to compile c codes using a jailbroken iphone4, the same process should work also on iphone3/3gs:)
If you want install/execute an application on a Iphone the possible ways are 2: via appstore or via cydia; so, how can i run an extern application on my iphone? Simple,compiling the application using the gcc compiler:)

before you continue you need to say that the iphone must be 'jailbroken' and, if you want use the compiter, one active connection ssh with the phone, for do this search 'Openssh iphone' on google for more info.
The procedure shown below can also be made with an ssh connection with the phone, however i like do this steps directly on iphone :)

Here we go:

1– On your iphone install and run a mobile terminal by cydia.

2– Moving with cd in a working directory (for example cd /var/mobile/Media/redo86), and type su to have a super user privileges.

3– Download and install fake–libcc ; using wget command:
           wget <LINK> –to download–
           dpkg –i fake–libgcc* –to install it–

4– Install iphone gcc compiler by cydia, or using apt command in the terminal:
           apt–get install iphone–gcc

5– Download the sdk package: sdk–2.0–headers.tar.gz using wget command like shown before.

6– Untar the file using:
           tar –xvzf sdk–*

7– Enter in the new created folder using cd command.

8– Copy all files to include folder typing:
           cp –r * /usr/include

9– Return to the previous folder typing cd ..

10– Download gcc files using wget:
           wget http://redo86.altervista.org/downloads/gcciphone.tar.gz

11– Untar the file:
           tar –xvzf gcc*

12– Enter in the new created folder and type:
           cp –r * /usr/lib

13– Make a simple hello world to see if all went well, i've used nano to do this:
           apt–get install nano
           nano hello.c

           #include <stdio.h>
           int main(){
                printf("Hello world");
                return 0;
           }


14– Save, exit and type:
           gcc hello.c –o hello

15– If all gone well you can run typing:
           ./hello

16– Enjoy :D

So, now you can execute (almost) all c program on your apple smartphone; so you just have to try and have fun :)
Bye bye




Important

The use of this material at the expense of others is absolutely not approved by badnack, which is not considered in any way responsible for any damage caused by improper use of the material. Copies of the above links are for illustrative purposes only and are posted only for for educational purposes