Compile C applications with gcc on iOS 4 (iPhone)
I search a lot on internet how to do this, and I found some info from Anastas Stoyanovsky. Most people posted that if you install libgcc on iOS 4 it will crash at boot but this is not true.
Here is what you need to do in order to be able to compile and run a C application on iphone:
1. You will need to Jailbreak the iPhone first, search on google for more info.
2. Install OpenSSH from Cydia.
3. Connect iPhone to your wireless network and SSH to it.
4. Download this application using: wget http://www.syshalt.net/pub/iphone/gcc-iphone/fake-libgcc_1.0_iphoneos-arm.deb
5. Install libcc using: dpkg –i fake-libgcc_1.0_iphoneos-arm.deb
6. Install iphone-gcc using this command: apt-get install iphone-gcc
(you can download this version from my website: iphone-gcc if does not work on your device the one that is installed by default)
7. Download using: wget http://www.syshalt.net/iphone/gcc-iphone/sdk-2.0-headers.tar.gz
8. Untar with command: tar -xvzf sdk-2.0-headers.tar.gz
9. Enter in the new created folder with: cd include-2.0-sdk-ready-for-iphone
10. Copy all files to include folder with command: cp –r * /usr/include
11. Now type: cd .. in order to return to the previous folder
12. Download using: wget http://www.syshalt.net/iphone/gcc-iphone/gcc_files.tar.gz
13. Untar with command: tar -xvzf gcc_files.tar.gz
14. Enter in the new created folder with command: cd gcc_files
15. Copy all files to /usr/lib using command: cp –r * /usr/lib
16. Install ldid to sign the application (this will prevent iOS to kill the application at startup) using: apt-get install ldid
17. Sign your compilet aplication using: ldid –S <application>
18. Run the application using: ./<application>Suggestion: Install using: apt-get install nano
This will help you code easy directly from terminal.
Here is an example of hello world using C and gcc to compile on iPhone iOS 4:
I used nano hello.c in terminal to open a new files and writed this simple application:
#include <stdio.h>
int main()
{
printf("hello, world\n");
return 0;
}
and then CTRL+X to save it, then I typed: gcc –o hello hello.c and after that ldid –S hello
Now you can run your application using ./hello
September 24th, 2011 - 21:29
Does it compile C++? Cuz I’m getting some errors.
December 6th, 2011 - 20:38
Thank you!
Works perfect
December 18th, 2011 - 01:49
Have you tried compiling objective c? I get an error
ld: library not found for -lobjc
collect2: ld returned 1 exit status
make: *** [HelloWorld] Error 1
It seems that iphone-gcc does not come with objective c support
December 29th, 2011 - 02:02
thank you!!!
January 14th, 2012 - 09:48
I can’t thank you enough for this, it has made hours of searching finally end favorably!
February 11th, 2012 - 06:11
Si ca ne marche pas , installer ca http://code.google.com/p/iphone-gcc-full/
February 13th, 2012 - 03:46
Thank you! Works great. Any chance of including gfortran as well?
February 13th, 2012 - 04:42
Thanks! Works great! Any chance to include gfortran as well?
March 5th, 2012 - 14:59
Will the above tutorial work on ipad2 with iOS5 ?? ..
please some one inform
March 6th, 2012 - 08:36
I’m getting errors in the studio.h header
March 6th, 2012 - 08:45
This rules. Can one link to the full framework toolchain?
March 8th, 2012 - 06:04
It worked on the iPad2 with ios5.
Thanks a lot, great tutorial !
May 27th, 2012 - 22:17
Thank you !~~
Finding libSystem.B.dylib everywhere……
June 13th, 2012 - 15:37
Work like a charm!
Thanks a lot.
June 17th, 2012 - 17:12
You can install Gcc in Cydia too just after install, and when compiling don’t forget to sign your app withing an iPad/2/iPhone by
compiling: gcc -o outPutName AppName.c
signing : ldid -S outPutName
Runing: ./outPutName
August 8th, 2012 - 05:21
Ipad 2, ios 5.1.1 and this worked great. Thank you
August 18th, 2012 - 04:37
ipad ios 5.1.1 – hello world works at least
Thanks-
September 14th, 2012 - 12:06
thanks so much, your guide turned the process from nightmarish to a kid’s game
have a good day
September 24th, 2012 - 10:49
@Matt … studio.h??? That may be your error. It’s stdio.h.
October 18th, 2012 - 07:02
The libstdg++.dylib is missing in the fake libgcc,hence cant compile c++.can u give any solution,please?thanks in advance.
February 22nd, 2013 - 17:05
libgcc_s_6 is not found by ld/as
any idea where to get one?
March 28th, 2013 - 16:58
thanks worked finally yay
I spent 10 hours and 2 nights trying to get it’s going before I found your site I wwas about to give up!
March 29th, 2013 - 20:39
@Darius, glad this post helped you.