Dev:Theos/Setup

This page contains instructions for installing Theos and preparing a new project.

Definitions
is the directory where Theos is installed on your machine. It is platform dependent.

Requirements

 * A modern operating system (Mac OS X, iOS [jailbroken], Windows [using Cygwin], and most variants of Linux should work) with the following set of utilities:
 * curl
 * git
 * make
 * openssh
 * perl
 * rsync
 * python (if on Windows)
 * Some form of a toolchain or official SDK
 * Access to a terminal emulator and some knowledge of how to use it
 * Objective-C knowledge

More detailed explanations of these requirements are given in the next section, and are dependent on the environment you use.

For Mac OS X
Mac OS X comes with most of the necessary tools (subversion, curl, and perl) by default. You will still need compilation tools and the iOS SDK, and the easiest way to obtain both of these is by installing Xcode from the App Store. Consider installing Command Line tools for Xcode as well, as it contains numerous tools that complement Xcode.

For Linux
Like OS X, most distributions come pre-packaged with the aforementioned tools. On Debian-based distros, APT can be used to install the tools like so: sudo apt-get install git perl curl

If your distro uses RPM, the process is very similar.

For iOS
Dependencies:

Theos as a package depends on bash, grep, dpkg, coreutils, ldid, rsync and make, so the utilities mentioned in the requirements are automatically installed.

Install a Toolchain:

See On-device toolchains for details.

Also for Linux and iOS (and other operating systems other than Mac OS X): Retrieving SDKs
If you aren't using OS X, you must download an iOS SDK. See Retrieving SDKs for details on this.

Take the SDK and put it in  (if it does not exist, create it), with a folder name like iPhone7.0.sdk. As of version 0.9.523, Theos accepts multiple SDKs in that folder.

Each SDK folder should have these folders: Developer, System, usr; and these files: ResourceRules.plist, Entitlements.plist, SDKSettings.plist.

Note that if no SDKs are provided, the following error will be displayed (also noted in the "Troubleshooting" section below): ".../theos/makefiles/targets/darwin-arm/iphone.mk:21: *** first argument to 'word' function must be greater than 0. stop."

On Mac OS X or Linux

 * 1) Open a terminal window.
 * 2) Choose a location for Theos to be installed. If you are unsure, a good choice is /opt/theos. export THEOS=/opt/theos
 * 3) * If you chose a location outside of your user's home directory, you will probably need to run some or all of the following commands with root permissions.
 * 4) Download the latest version of Theos:
 * 5) * Using git: git clone git://github.com/DHowett/theos.git $THEOS
 * 6) * Alternatively, you can use svn, if you prefer: svn co http://svn.howett.net/svn/theos/trunk $THEOS
 * 7) Download ldid to $THEOS/bin: git clone git://git.saurik.com/ldid.git&#10;cd ldid&#10;git submodule update --init&#10;./make.sh&#10;cp -f ./ldid $THEOS/bin/ldid
 * 8) Add Theos environment variables to your   (or the equivalent for your shell). Open   (create it if it does not exist) in your favorite editor and add this on the last line, replacing the device name with your own device's name (replacing spaces with dashes) or its IP address:  export THEOS=/opt/theos&#10;export THEOS_DEVICE_IP=example.local THEOS_DEVICE_PORT=22 (To get your device's IP address, go to settings, Wi-Fi, then press the i on the network you are currently connected on, and then see where it says IP Address. This is what you type in, if you don't want to use a device name.) Load this into the shell with , or close the terminal window and launch a new one.
 * 9) As the Substrate library does not come installed on these platforms nor bundled with Theos, copy   from the device to your local   folder and rename it to  . (If you don't do this step, or if you use an old version of Substrate, or if something else goes wrong, you may get one of these error messages). Similarly, copy   to your local   folder and rename it to.

On iOS
(On your iOS device:)


 * 1) Create a file at /etc/apt/sources.list.d/coredev.nl.list containing the following line: deb http://coredev.nl/cydia iphone main
 * 2) Create a file at /etc/apt/sources.list.d/howett.net.list containing the following line: deb http://nix.howett.net/theos ./
 * 3) Make sure APT 0.6 Transitional Package is installed before doing this step. As root, issue these commands (using either SSH or MobileTerminal): apt-get update  apt-get install perl net.howett.theos

Creating a Project
Theos lets you create new projects based on templates using the New Instance Creator (NIC). You do not need to be root to do this step, nor should you be. Start the NIC wizard using the following command:

$THEOS/bin/nic.pl

NIC will prompt you for all the necessary information before creating a project. Please make sure that the path to your current directory doesn't have spaces in it.

(If you get an error message saying "Illegal instruction: 4", see this troubleshooting advice.)

NIC Example
Here is an example of what you will see when using the NIC to create a project (with user input shown in bold):

$ $THEOS/bin/nic.pl NIC 1.0 - New Instance Creator --  [1.] iphone/application [2.] iphone/library [3.] iphone/preference_bundle [4.] iphone/tool [5.] iphone/tweak Choose a Template (required): 1 Project Name (required): iPhoneDevWiki Package Name [com.yourcompany.iphonedevwiki]: net.howett.iphonedevwiki Authour/Maintainer Name [Dustin L. Howett]: Instantiating iphone/application in iphonedevwiki/... Done. $

The above will create a folder ./iphonedevwiki in the current working directory - make sure you have permissions to create a folder.

Making your Project
When you have finished developing your tweak/app, you may want to distribute it, either to your own device, or to an external source.

When you are making the project, type this in the terminal, in your project folder:

$ make package

This will generate a .deb file, which you can distribute to people or to repositories.

If you want to install the latest package, type:

$ make install

It will then ask for your root password and install the .deb onto your device. If you haven't changed your root password, the default password is alpine. Make sure you change your root password, which you can do with passwd (see "Root Password How-To" on the Cydia homepage for detailed instructions).

Getting Help
If you need further assistance, or if you have other questions about Theos itself, feel free to connect to #theos on irc.saurik.com using your preferred IRC client. If you don't already have a preferred IRC client, you can learn more here: IRC.

Missing SDK
If you get this message:

".../theos/makefiles/targets/PPP/iphone.mk:21: *** first argument to 'word' function must be greater than 0. stop."

PPP is the platform of the working machine.

It means that you don't have SDKs in. See this section.

Small SDK
If you get this message:

ld: file too small (length=LLL) file. '.../theos/sdks/iPhoneOSX.Y.sdk/usr/ZZZ' for architecture armAAA.

LLL is a size, potentially 0 on most cases, X & Y are sdk version, ZZZ is a file path, AAA is architecture suffix (v6, v7, v7s, 64).

It probably means that you have a faulty SDK in some way. One common mistake, while using Theos on an iOS device, is to extract the SDK on a PC and then copy over the files. This usually results in various errors in the extraction that translate in not being able to compile. Instead, copy the SDK in the compressed form and extract it on the device. Do not worry if this takes time, it will preserve all file attributes.

Missing Substrate header
If you get this message:

FFF:LLL:10: fatal error: 'substrate.h' file not found ^ 1 error generated.
 * 1) include 

LLL is a line number, FFF is a file path.

This means that you are missing the Substrate header (see step #6 in setting up Theos for OS X or Linux). To fix this you need to copy  to your local   folder and rename it to.

Missing Substrate library
If you get either of these messages:

Bootstrapping CydiaSubstrate... Compiling iPhoneOS CydiaSubstrate stub... default target? failed, what? cp: cannot stat ‘_out/*’: No such file or directory cp: cannot stat ‘libsubstrate.dylib’: No such file or directory

Or

ld: warning: ignoring file .../theos/lib/libsubstrate.dylib, file was built for armXXX which is not the architecture being linked (armYYY): .../theos/lib/libsubstrate.dylib

XXX and YYY are architecture suffixes (v6, v7, v7s, 64).

This means that you are missing the Substrate library to link with (see step #6 in setting up Theos for OS X or Linux) or you have an old version of the library. Either way, get an up-to-date version of the file from the device at, copy it to your local   folder, and rename it to.

More detail about how to fix this:

OS X and Linux users can use the following command to copy the file (using the scp program), where   should be replaced with the IP address of your device where you have Substrate installed:

Windows users can use WinSCP to connect to the device's IP address to locate the file and copy it over to their Theos installation.

iOS users usually don't have this problem because they usually already have Substrate installed. However, they can have an outdated version of Substrate and need to update it.

Architecture (partial) incompatibility
If you get this error while attempting to run the Theos New Instance Creator (NIC):

Illegal instruction: 4

It probably means you are using versions of tools that work on older devices but not on new ones. Read more on the issue here.

It usually affects perl and rsync (installed from the default sources), so to fix this, run these commands as root on the device using SSH or MobileTerminal:

sed -i'' 's/\x00\x30\x93\xe4/\x00\x30\x93\xe5/g;s/\x00\x30\xd3\xe4/\x00\x30\xd3\xe5/g;' /usr/bin/perl; ldid -s /usr/bin/perl sed -i'' 's/\x00\x30\x93\xe4/\x00\x30\x93\xe5/g;s/\x00\x30\xd3\xe4/\x00\x30\xd3\xe5/g;' /usr/bin/rsync; ldid -s /usr/bin/rsync

Spaces in Path
While building a project mostly works even if the path to the project contains spaces,  will fail. Make sure you don't have spaces in the project path.

Undefined platform
If you get this message:

theos/makefiles/common.mk:103: *** You did not specify a target, and the "" platform does not define a default target. Stop.

It probably means you are using a platform unsupported by Theos. If you are using iOS as a platform and on a 64bit device, you are probably getting this error. To fix this, you can do the following:

sudo ln -s $THEOS/makefiles/platform/Darwin-arm{,64}.mk