Saturday, January 21, 2012

Install C Compiler on iPhone 4S [GCC Installer Script]

Like MSF Installer Script, i made little update to GCC Installer Script, i tested it and it works well. And it works the same as MSF Installer Script, we need to download the script via wget, make it executable and execute it. So before you start, make sure you have wget and aptitude installed(install them from Cydia), and we need ssh connection to install the script(or if you have MobileTerminal, you can install it directly from there).

To use script, connect to your device via SSH, and download the script by the following:

wget http://khalil_ounis.byethost4.com/gcc_installer_v3.sh


Make it executable by:

chmod +x gcc_installer_v3.sh


Executing the script

./gcc_installer_v3.sh


And that's it, all you have to do now is compile your c program, and use the following command before you execute it:

ldid -S YourProgramName


and execute your c program:

./YourProgramName




Hope i helped :), this is source code of the script:

#!/bin/bash
# Author: Khalil Ounis (Algeria)
# Thnx to: www.syshalt.net
# Web Site: www.89geek.com

ROOT_UID=0
VARDIR=/private/var/
CURRDIR=`pwd`
E_NODIR=1
E_NOTROOT=67
E_CMDNOTFOUND=127

clear

[ "$UID" != "$ROOT_UID" ] && {
echo "This script must be run as root";
exit $E_NOTROOT;
}

echo "GCC Installer Script - By Khalil Ounis (www.89geek.com)"
echo "Thanks To www.syshalt.net for the instructions"
echo "Press any key to continue..."
read

cd $VARDIR &> /dev/null
[ $? -eq $E_NODIR ] && {
echo "Can't access to $VARDIR, check your folder.";
exit $E_NODIR;
}

wget &>/dev/null
[ $? -eq $E_CMDNOTFOUND ] && {
echo -n "wget not installed. Installing wget... ";
aptitude -y wget &>/dev/null;
echo "Done"
}

echo -n "Download fake-libgcc_1.0_iphoneos-arm.deb... "
[ -f fake-libgcc_1.0_iphoneos-arm.deb ] && rm fake-libgcc_1.0_iphoneos-arm.deb &>/dev/null
wget http://www.syshalt.net/iphone/gcc-iphone/fake-libgcc_1.0_iphoneos-arm.deb &>/dev/null
echo "Done"

echo -n "Download sdk-2.0-headers.tar.gz... "
[ -f sdk-2.0-headers.tar.gz ] && rm sdk-2.0-headers.tar.gz &>/dev/null
wget http://www.syshalt.net/iphone/gcc-iphone/sdk-2.0-headers.tar.gz &>/dev/null
echo "Done"

echo -n "Download gcc_files.tar.gz... "
[ -f gcc_files.tar.gz ] && rm gcc_files.tar.gz &>/dev/null
wget http://www.syshalt.net/iphone/gcc-iphone/gcc_files.tar.gz &>/dev/null
echo "Done"

echo -n "Installing fake-libgcc_1.0_iphoneos-arm.deb... "
dpkg -i fake-libgcc_1.0_iphoneos-arm.deb &>/dev/null
echo "Done"

echo -n "Removing fake-libgcc_1.0_iphoneos-arm.deb... "
rm -rf fake-libgcc_1.0_iphoneos-arm.deb &>/dev/null
echo "Done"

echo -n "Installing iphone-gcc and ldid... "
aptitude -y install iphone-gcc ldid &>/dev/null
[ $? -eq $E_CMDNOTFOUND ] && {
echo "aptitude not installed, use cydia to install it.";
echo "installation aborted.";
exit $E_CMDNOTFOUND;
}

echo "Done"

echo -n "Decompressing sdk-2.0-headers.tar.gz... "
tar -xvzf sdk-2.0-headers.tar.gz &>/dev/null
[ $? -ne 0 ] && {
echo "Problem occurred while decompressing archive.";
echo "installation aborted";
exit 1;
}
echo "Done"

cd "include-2.0-sdk-ready-for-iphone"
cp -r * /usr/include
cd ..
rm -rf "sdk-2.0-headers.tar.gz" "include-2.0-sdk-ready-for-iphone"

echo -n "Decompressing gcc_files.tar.gz... "
tar -xvf gcc_files.tar.gz &>/dev/null
[ $? -ne 0 ] && {
echo "Problem occurred while decompressing archive.";
echo "installation aborted";
exit 1;
}
echo "Done"

echo -n "Just few steps... "
cd gcc_files
cp -r * /usr/lib
cd ..
rm -rf gcc_files.tar.gz gcc_files

echo "Done"

cd $CURRDIR
clear
echo "Done... GCC Installed"

exit 0


Good luck!

21 comments :

  1. Hey great work it seams.. however I cant seam to be able to install gcc..

    Im running on appletv2 and everything have been installing so far, I have perl, php, lightppd etc running and all works good..

    So I run your script and looks like it installs:

    server05:/private/var/root/Scripts root# ./gcc_installer_v3.sh

    GCC Installer Script - By Khalil Ounis (www.89geek.com)
    Thanks To www.syshalt.net for the instructions
    Press any key to continue...

    Download fake-libgcc_1.0_iphoneos-arm.deb... Done
    Download sdk-2.0-headers.tar.gz... Done
    Download gcc_files.tar.gz... Done
    Installing fake-libgcc_1.0_iphoneos-arm.deb... Done
    Removing fake-libgcc_1.0_iphoneos-arm.deb... Done
    Installing iphone-gcc and ldid... Done
    Decompressing sdk-2.0-headers.tar.gz... Done
    Decompressing gcc_files.tar.gz... Done
    Just few steps... Done

    Then next I try a simple .c like hello.c

    I get :-sh: gcc: command not found

    when I search for gcc:
    root# find / -name gcc

    I find only:

    /private/var/root/Scripts/include-2.0-sdk-ready-for-iphone/gcc
    /private/var/stash/include/gcc
    /private/var/stash/libexec/gcc

    What am I doing wrong? any help would be apchated, thanks.. :-)

    /Frank

    frank121272 @ gmail dot com

    ReplyDelete
  2. Hi frank, don't worry we will get it work :)

    Tell me what you get when you type the following:

    aptitude -y install iphone-gcc

    ReplyDelete
  3. I get the following:

    server05:/private/var/root/Scripts root# aptitude -y install iphone-gcc
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Reading extended state information
    Initializing package states... Done
    Building tag database... Done
    No candidate version found for iphone-gcc
    No candidate version found for iphone-gcc
    No packages will be installed, upgraded, or removed.
    0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    Need to get 0B of archives. After unpacking 0B will be used.
    Writing extended state information... Done
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Reading extended state information
    Initializing package states... Done
    Building tag database... Done

    So it seams im missing an source?

    ReplyDelete
    Replies
    1. Ok, i guess we have to download and install gcc manually, do the following:

      wget http://apt.saurik.com/debs/iphone-gcc_4.2-20090304-1-9_iphoneos-arm.deb

      dpkg -i iphone-gcc_4.2-20090304-1-9_iphoneos-arm.deb

      Delete
    2. I tryed that just now with iphone-gcc_4.2-20080604-1-8_iphoneos-arm.deb, that gave me an error.. So I tryed the one you linked wget http://apt.saurik.com/debs/iphone-gcc_4.2-20090304-1-9_iphoneos-arm.deb

      Then I get:

      server05:/private/var/root/Scripts root# dpkg -i iphone-gcc_4.2-20090304-1-9_iphoneos-arm.deb
      Selecting previously deselected package iphone-gcc.
      (Reading database ... 14117 files and directories currently installed.)
      Unpacking iphone-gcc (from iphone-gcc_4.2-20090304-1-9_iphoneos-arm.deb) ...
      dpkg: dependency problems prevent configuration of iphone-gcc:
      iphone-gcc depends on csu; however:
      Package csu is not installed.
      dpkg: error processing iphone-gcc (--install):
      dependency problems - leaving unconfigured
      Errors were encountered while processing:
      iphone-gcc


      gcc seam to be installed now ore partly but its not working, I get:

      server05:/private/var/root/Scripts root# gcc -o serveron serveron.c

      ld: library not found for -lcrt1.10.5.o
      collect2: ld returned 1 exit status

      its the with something else as gcc -o hello hello.c

      Delete
  4. Replies
    1. Download it and install it:

      wget http://apt.saurik.com/debs/csu_232-2_iphoneos-arm.deb

      dpkg -i csu_232-2_iphoneos-arm.deb

      and you may need to re-install gcc

      Delete
  5. ohsnap super it worked :-)) thank you so much :-)

    btw do you have much experince with appletv2 ? I keep running out of space.. and I dont know what I dare to delete haha :-) I removed some fonts and frameworks like voiceservice and screensaver.. its seam to make no diffense since im not booting up gui.

    I have installed mysql cus I dont like sql lite, but I just need the ruby too, just I run out of space.. again..

    /Frank

    ReplyDelete
  6. Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/disk0s1s1 582472 561576 15072 98% /
    devfs 26 26 0 100% /dev
    /dev/disk0s1s2 7199928 620360 6579568 9% /private/var

    ReplyDelete
  7. Glad that it worked for you :)

    i never worked on appletv... it's always a problem with the size of the root patition(in all iDevices), the better choice is creating a custom firmware and change the root partition size, or you can remove unwanted languages files(you will save some space).

    ReplyDelete
  8. Hello Khalil,
    when i installed Gcc on IOS 5.1, i tried to compile a simple Hello world c file, it works, but when running, it send me this output: killed: 9
    Do you know what is this problem ?
    thanks

    ReplyDelete
    Replies
    1. Hi mahdi, killed 9 means the executable is not digitally signed by apple, anyway, you tried to execute your program directly.

      first you have to sign your program with ldid:

      ldid -s YourProgramName

      after that you can execute your program

      ./YourProgramName

      Good luck :)

      Delete
    2. Another problem :/

      iPad-de-Mahdi:/private/var/mahdi root# gcc Hello.c -lpcap -o mahdinio
      iPad-de-Mahdi:/private/var/mahdi root# ldid -s mahdinio
      util/ldid.cpp(660): _assert(78:signature != NULL)
      iPad-de-Mahdi:/private/var/mahdi root# ./mahdinio
      Killed: 9

      Delete
    3. Thanks for the heads up mahdi, it's

      ldid -S YourProgramName

      Delete
  9. which text editor do we use???

    ReplyDelete
    Replies
    1. for me, i use nano editor, and of course via SSH

      Delete
  10. hey dude you are ovesome:) i#v resored iphone then i have foloved your tutorial,and i have get it wort compiling c apps, i#v downloded your script,libgcc++ iphone os c/c++ compiler. start iphone c/c++ compiler, and ger an error, then i have copy /usr/lib/ '4 files in the directory:' libsupc++.a, libsubstrate.dylib libstdc++.6.dylib libstdc++.6.0.9.dylib with iphone c/c++ compiler i#v get error, then i cydia downloaded iphone 2.0 toolchane, and i can run c++ app whitout erroe including istream, not iostream.h

    ReplyDelete
    Replies
    1. Thank you my friend :) and good luck

      Delete
  11. I have an error: "util/ldid.cpp(249) : _assert(78:Swap(machheader->magic) == MH_MAGIC)

    ReplyDelete