You are on page 1of 8

3/24/2011 Compile C applications with gcc on iOS 4…

IT NEWS, TUTORIALS, SOLUTIONS – SYSTEM


HALT
Subscribe via RSS

HOME

Compile C applications with gcc on iOS 4 (iPhone) Follow me on Twitter

I search a lot on internet how to do this, and I found some info from Anastas Stoyanovsky. @jcf_dev ipad1 and iphone 3gs
Most people posted that if you install libgcc on iOS 4 it will crash at boot but this is not true. 2011/03/22

Jailbreak iOS 4.3b2 on iPad tethered


Here is what you need to do in order to be able to compile and run a C application on iphone: and fully working http://bit.ly/hi0gcB
2011/02/01

1. You will need to Jailbreak the iPhone first, search on google for more info. Updated to iOS 4, nice release from
2. Install OpenSSH from Cydia. them, battery lasts longer now.
3. Connect iPhone to your wireless network and SSH to it. 2010/06/29
4. Download this application using: wget http://www.syshalt.net/pub/iphone/gcc-
iphone/fake-libgcc_1.0_iphoneos-arm.deb
Recent Posts
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 Disable iOS 4 services. Optimize your
(you can download this version from my website: iphone-gcc if does not work on your iPhone, iPod, iPad and save memory.
device the one that is installed by default)
7. Download using: wget http://www.syshalt.net/iphone/gcc-iphone/sdk-2.0- greenp0ison RC5 libcurl.4.dylib
headers.tar.gz “Incompatible library version:
8. Untar with command: tar -xvzf sdk-2.0-headers.tar.gz greenpois0n requires version 6.0.0”
9. Enter in the new created folder with: cd include-2.0-sdk-ready-for-iphone on OSX 10.5.8
10. Copy all files to include folder with command: cp –r * /usr/include
Install iOS 4.3b2 on iPad and jailbreak
11. Now type: cd .. in order to return to the previous folder
(tethered) – fully working
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 Prevent Winmail.dat in mail
14. Enter in the new created folder with command: cd gcc_files attachment (Exchange 2007)
15. Copy all files to /usr/lib using command: cp –r * /usr/lib
Blue Screen of Death (BSOD) on
16. Install ldid to sign the application (this will prevent iOS to kill the application at
Windows 2000 Server
startup) using: apt-get install ldid
17. Sign your compilet aplication using: ldid –S <application>
18. Run the application using: ./<application> Friends

* Thanks for Liero, he found that it is a bug in latest version of gcc from Saurik, so he Andrada Misca
provided us with a version that works. Catalin

Cristian Crisan
Suggestion: Install using: apt-get install nano
This will help you code easy directly from terminal. Marian Neagul

Here is an example of hello world using C and gcc to compile on iPhone iOS 4:
Archives

I used nano hello.c in terminal to open a new files and writed this simple application: February 2011

December 2010
#include <stdio.h>
int main() October 2010
{
September 2010
printf("hello, world\n");
return 0; May 2010
}
March 2009

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 Categories

Apple

CentOS

…syshalt.net/…/compile-c-applications-w… 1/8
3/24/2011 Compile C applications with gcc on iOS 4…
Exchange 2003/2007

iPad

iPhone

Linux

Microsoft

Others

Windows 2000

Windows Server 2003

Meta

Register

Log in

Entries RSS
Technorati Tags: ios4,jailbreak,iphone,apple,gcc,g++,programming,cydia,apt-get
Comments RSS
Tagged as: Anastas, c application, c applications, code, command cd, command cp, Leave a comment
command tar, Connect, cydia, deb, default, dpkg, gcc, google, include, info, WordPress.org
Install, int, ios, iphone, lib, Liero, lt, openssh, Saurik, sdk, search, startup,
suggestion, tar gz, terminal, type, type cd, Untar, wget
Statistics
Today visits: 32

Tags
Comments (28) Trackbacks (2) ( subscribe to comments on this post )

3b2 apple beta lt blobs button


chown com Connect cydia
shadow developer account DFU
September 16th, 2010 - 19:38
download easly follow
apt-get pe iphone… genial. instructions future gcc hosts

Scrie și tu în românește nu te mai prosti!


iDevice images Install iPad
iphone ipod iTunes key lib
LinkedIn mac press

Walter Nelson openssh phone plist power


October 9th, 2010 - 03:55 button Press reboot recovery mode

THANK YOU SO MUCH! I LUV U! NVM, BUT THANKS! redsn screen search system
library terminal test time
TinyUmbrella wheel windows c

geekstrada
October 15th, 2010 - 05:03

Very, very cool.

Nathan Broadbent
October 16th, 2010 - 13:36

Awesome tutorial, works perfectly

Carlo
November 18th, 2010 - 16:09

Hello Sergiu.
Thanks a lot for your instructions on compiling C apps on iOS 4. Before I found your site, I
…syshalt.net/…/compile-c-applications-w… 2/8
3/24/2011 Compile C applications with gcc on iOS 4…
Thanks a lot for your instructions on compiling C apps on iOS 4. Before I found your site, I
had spent so much time on this issue without success. Great help probably not only for
me, but for all those in the community who get to know that compiling on iPhone 4 is
much more pleasure than on the weaker earlier models.

Hm, well… may I nevertheless dare to ask for an additional thing?: Do you know about
anybody working on something similar for C++? At least, all my efforts end up in linker
errors indicating libraries being missing.

James
November 28th, 2010 - 19:05

Thanks for your instructions,


I follow your instructions to install without any error,
but when i compile hello.c shows errors as follow…..
Would you please help me?

Thanks a lot

xJames-i4:~ root# gcc -o hello hello.c

In file included from /usr/include/stdio.h:64,


from hello.c:1:
/usr/include/_types.h:27:24: error: sys/_types.h: No such file or directory
In file included from hello.c:1:
/usr/include/stdio.h:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘va_list’
/usr/include/stdio.h:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘off_t’
/usr/include/stdio.h:80: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘size_t’
/usr/include/stdio.h:87: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fpos_t’
/usr/include/stdio.h:145: error: expected specifier-qualifier-list before ‘fpos_t’
/usr/include/stdio.h:171: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
/usr/include/stdio.h:248: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__BEGIN_DECLS’
/usr/include/stdio.h:255: error: expected declaration specifiers or ‘…’ before ‘fpos_t’
/usr/include/stdio.h: In function ‘fprintf’:
/usr/include/stdio.h:258: error: expected declaration specifiers before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:260: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_ALIAS’
/usr/include/stdio.h:261: error: expected declaration specifiers before ‘size_t’
/usr/include/stdio.h:263: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_ALIAS’
/usr/include/stdio.h:264: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:266: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
/usr/include/stdio.h:268: error: expected declaration specifiers before ‘size_t’
/usr/include/stdio.h:273: error: storage class specified for parameter ‘sys_nerr’
/usr/include/stdio.h:274: error: storage class specified for parameter ‘sys_errlist’
/usr/include/stdio.h:277: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:284: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:286: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/include/stdio.h:287: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:288: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:292: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:292: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:293: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:293: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:294: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:294: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
…syshalt.net/…/compile-c-applications-w… 3/8
3/24/2011
‘__DARWIN_LDBL_COMPAT’ Compile C applications with gcc on iOS 4…
/usr/include/stdio.h:296: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:297: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:297: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:299: error: expected declaration specifiers before ‘__END_DECLS’
/usr/include/stdio.h:314: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/include/stdio.h:323: error: expected declaration specifiers or ‘…’ before ‘off_t’
/usr/include/stdio.h:324: error: expected declaration specifiers before ‘off_t’
/usr/include/stdio.h:341: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/include/stdio.h:341: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:342: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_ALIAS’
/usr/include/stdio.h:343: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:343: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:344: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:344: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:345: error: expected declaration specifiers or ‘…’ before ‘size_t’
/usr/include/stdio.h:345: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:345: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:346: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:346: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:350: error: expected declaration specifiers before ‘__END_DECLS’
/usr/include/stdio.h:362: error: expected declaration specifiers before ‘__END_DECLS’
/usr/include/stdio.h:373: error: expected declaration specifiers or ‘…’ before ‘va_list’
/usr/include/stdio.h:373: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
‘__DARWIN_LDBL_COMPAT’
/usr/include/stdio.h:375: error: expected declaration specifiers before ‘__END_DECLS’
hello.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{‘ token
hello.c:6: error: old-style parameter declarations in prototyped function definition
/usr/include/stdio.h:258: error: parameter name omitted
/usr/include/stdio.h:258: error: parameter name omitted
hello.c:6: error: expected ‘{‘ at end of input

James
November 29th, 2010 - 04:39

Thanks Nathan~
I reinstall again and it works,

3L173 Darkra1gne
December 3rd, 2010 - 16:49

Good guide I like ur style. Fed up of people asking how it’s done about time sum1 took the
masses through it step by step. Now all we need is to come up with a way of developing a
step by step guide to creating new programs lol. And put Microsoft apple and all those
other software theefs out of business. Every 1 use unix Linux and say no to close source
inferia bs.

but keep it legal


Peace
Salaam
Shalom

Erik Séguin
…syshalt.net/…/compile-c-applications-w… 4/8
3/24/2011 Compile C applications with gcc on iOS 4…
Erik Séguin
December 12th, 2010 - 06:57

I can’t thank you enough! Thanks so much!

Nikola
December 16th, 2010 - 01:08

@James: How you fixed the error (Ive done the hole process 2 times and it still gives me
the same errors when compiling…)

In file included from /usr/include/stdio.h:64,


from hello.c:1:
/usr/include/_types.h:27:24: error: sys/_types.h: No such file or directory
In file included from hello.c:1:
/usr/include/stdio.h:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘va_list’
/usr/include/stdio.h:75: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’

Thanks

Nikola
December 16th, 2010 - 01:13

was missing line “9. Copy all files to include folder with command: cp –r * /usr/include”

Qantum251
December 18th, 2010 - 15:49

Thanks thanks thanks…!i’ve been looking for that trick since i bought that bad phone but
now worth it, just one thing….you’re one hell of C bloogger this’s Great now i can C

gobsmack
December 24th, 2010 - 03:22

I agree, very well done post. A couple things I encountered –

I had to “chmod” all the directories under /usr/include to 755 to allow them to be read by
the compiler:
find /usr/include -follow -type d -exec chmod 755 {} \;
Maybe because I installed everything as root and compiled as mobile?

I didn’t have to “ldid -S” in order to run the resulting hello command.

I noticed several times that being in cydia on my iPad at the same time I tried to install
something from the command line would interfere with the install. I got errors like this:
Rons-iPad:~ root# apt-get install ldid
E: Could not get lock /var/lib/dpkg/lock – open (35: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Hopefully this will help someone else avoid these errors.

Cheers!

Sergiu Moza
December 25th, 2010 - 21:56
…syshalt.net/…/compile-c-applications-w… 5/8
3/24/2011 December 25th, 2010 - 21:56 Compile C applications with gcc on iOS 4…

gobsmack, Cydia uses dpkg so you wont be able to use apt-get as long as the application
is opened. cydia is slow, so if you want to keep you applications updated just use apt-get
update and then apt-get upgrade in order to keep applications up to date (those who were
installed with cydia)

Celtrix
December 30th, 2010 - 22:26

Thanks for the info does this successfully implement the STD C library?

Jeremy
January 3rd, 2011 - 08:49

Thanks for the steps. Just two questions:


(1) I use Ubuntu and Windows 7. I do not have a Macbook. Does your example require
Macbook to work?
(2) I cannot find gcc on Cydia. I press on Cydia icon. Then I see “Home – Cydia” screen.
The information displayed at the bottom says: iPhone 4, iOS 4.1, Cydia 1.0.3222-73
I then press “Search”. I key in “GCC”, “GNU”, “Compiler”, “iphone gcc”, “iphone-gcc” and
nothing gives me gcc. How do I install gcc on Cydia if it is not listed?

Thanks

Sergiu Moza
January 3rd, 2011 - 23:14

hi there,

please follow exactly the guide:

1. your phone needs to be jailbreaked, and you can use guide both on windows, linux,
mac.
2. u need to jailbreak the iphone then install openssh from cydia.
3. read guide careful:
—- Connect iPhone to your wireless network and SSH to it (using putty or any other ssh
client).
—- Download this application (from terminal) using: wget
http://www.syshalt.net/iphone/gcc-iphone/fake-libgcc_1.0_iphoneos-arm.deb
—- Install libcc using command: dpkg –i fake-libgcc_1.0_iphoneos-arm.deb
—- “Install gcc from Cydia with command (type this command in terminal): apt-get install
iphone-gcc”

Joe
January 8th, 2011 - 18:29

Anybody managed to compile C++ with that trick ?


I always get a ‘error: iostream: No such file or directory’ error…

ykee
January 12th, 2011 - 13:53

Many thanks for the guide. It works.

…syshalt.net/…/compile-c-applications-w… 6/8
3/24/2011 Compile C applications with gcc on iOS 4…

C0deH4cker
January 25th, 2011 - 22:47

@Jeremy

1) Mac is not necessary. This is just so your iPhone can compile c programs by itself.

2) Go to Cydia→Manage→Settings and make sure it says “Developer.”

Khalil Ounis
January 26th, 2011 - 11:17

Thank you very much for the instructions, i have just put those instructions in a bash
script, to make it easy to install for users, the guide is in this link:
http://www.89geek.com/?p=68, and thanks again author

Pete
February 15th, 2011 - 18:31

how can I remove fake-libgcc_1.0_iphoneos-arm.deb? Something went “south” while


installing it and I want to back it out

Sergiu Moza
February 15th, 2011 - 22:43

@Pete

dpkg -r fake-libgcc_1.0_iphoneos-arm.deb

Pete
February 15th, 2011 - 23:23

Thanks Sergiu, that’s what I did tried but it gives me no error messages and it does
nothing. I must have hosed something.. I’ll have to restore… oh well.

Nate
February 16th, 2011 - 07:21

I used this on an apple tv 2 (black) . Works great!! Thanks!!!

Liero
February 27th, 2011 - 08:22

Thanks for your specific tutorial!


But I have a problem on my own device.
I follow all your steps to No.15. I cannot find the command “gcc” with “which gcc”in my
ipod touch (iOS 4.1). And I also check several times that iphone-gcc has installed
correctly.
Could you help me with that?

…syshalt.net/…/compile-c-applications-w… 7/8
3/24/2011 Compile C applications with gcc on iOS 4…

Liero
February 27th, 2011 - 08:54

I have found the solution.


With command “apt-get install iphone-gcc”, the package ” iphone-gcc_4.2-20090304-1-
9_iphoneos-arm.deb” will be installed right now. But there is a bug in it. Install the
previous version will solve it. Type the command below:
wget http://apt.saurik.com/debs/iphone-gcc_4.2-20080604-1-8_iphoneos-arm.deb
dpkg -i iphone-gcc_4.2-20080604-1-8_iphoneos-arm.deb

You’d better add this to your article in case someone else has the same problem.
Thanks for your tutorial!

Nemo
March 17th, 2011 - 22:40

For those interested in g++: If you have access to the apple SDK you can find the headers
in the /Developers directory. You can just copy the contents of the C++ directory to
/usr/include/c++. Then also copy the libstdc++.dylib to /usr/lib, the g++ works.

Leave a comment
Name (required)

Email (required)

Website

Submit

Java on iOS 4 (iPhone) » « ITCongress 2010

C opy right © 2011 IT News, Tutorials, Solutions - SYSTEM HA LT · Powered by WordPress


Lightword Theme by Andrei Luca Go to top ↑

…syshalt.net/…/compile-c-applications-w… 8/8