Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.
iPhone / iPod Touch SDK | Development Discussionforums, a part of the
3rd Party Apps For iPhone | iPod Touchsection;
Setting up Xcode to compile your Mobile Substrate extensions I noticed that there is a severe lack of documentation for budding developers to get their development environment set up, and...
09-14-2010, 08:03 PM #1
[TUTORIAL] How To Compile Mobile Substrate Extension in Xcode
Setting up Xcode to compile your Mobile Substrate extensions
I noticed that there is a severe lack of documentation for budding developers to get their development environment set up, and I had thought for a long time that it was ridiculously difficult to do. Turns out that thanks to a template from a moderator at iPod Touch Fans named [ame="http://www.ipodtouchfans.com/forums/showthread.php?t=163185"]SkylarEC[/ame], it is actually pretty simple.
First things first
If you haven't a clue what words like "class" or "header" or even "compile" mean, you really shouldn't bother with this right now. Go pick up a book like Programming in Objective-C and read through it a bit. That's what I did for a few weeks in the summer and I at least /kind of/ know what I'm doing =P But seriously, if you just suck it up and run through Apple's "First iOS Application" guide, even that will help out immensely.
You will need a Mac with Xcode and (for the purpose of this guide) iOS SDK 4.0. This will almost without a doubt work on other versions, just adapt the instructions as such. You will also need to download the .zip I have provided, which contains all the stuff you'll need to get all set up.
Ok here we go
- Download and extract my zip: XcodeSubstrate.zip (if you would like to dump your own SpringBoard headers for a version other than iOS 4.0, download this zip instead, sans SB headers: XcodeSubstrateNoHeaders.zip)*
- Move the entire "SpringBoard" folder into ../Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/include/ (move the folder itself, not just its contents)
- Download substrate.h and put it in the same folder as you put the SpringBoard folder (don't actually put it INSIDE the SpringBoard folder)
- Move the entire "Mobile Substrate Extension" folder into ../Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/
- Move libsubstrate.dylib into ../Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/
- Open up Xcode and start a new project using the Mobile Substrate Extension template
- Make sure you change from Simulator to Device or it will give all sorts of missing file errors
- Everything should be ready to build! (Don't do Build and Run; instead, click Build from the menu bar and click Build)
After you build in Xcode, follow these steps to get your extension onto your iPhone:
- In Finder, open up your project folder
- Go into the build folder and then into either the Release-iphoneos or Debug-iphoneos folder, depending on which settings you used to compile
- Control-click the app (it will look like the applications "A" with a few sheets of paper and a "no" sign over it), then click Show Package Contents
- There will be a file in there with the same name as your project and no file extension; copy it to some other place
- Add the extension ".dylib" to the file
- Copy that file to /Library/MobileSubstrate/DynamicLibraries/ on your iPhone using an iPhone browser or SSH
- killall SpringBoard
If you're using a different version of the SDK (like 4.1)
If you do not have the 4.0 SDK installed, the Foundation and UIKit frameworks will appear red in the sidebar and it will not compile. If you wish to use a different SDK and have already adapted the rest of the guide for it, do this:
- In the menu bar, click Project > Edit Project Settings
- Click the "Build" tab at the top
- Drop down the Configuration box and change it to Debug
- Change the Base SDK to iPhone Device 4.0
- Drop down the Configuration box and change it to Release
- Change the Base SDK to iPhone Device 4.0
- Close the window
- Expand the Frameworks folder in the sidebar to reveal the red Foundation and UIKit frameworks, then delete them both
- Control-click the Frameworks folder > Add > Existing Frameworks...
- Choose Foundation and UIKit from the list
If you're like me you forget a lot of stuff a lot of the time. Most of the time when you're getting errors out of nowhere, especially starting a new project or importing a new header, you'll get errorz if you don't remember certain things. Some common things to check:[LIST][*]Make sure you're building to device and not simulator (unless you actually set up headers and stuff for the simulator). This will give you all sorts of errors saying all this stuff is missing, but it won't remind you that you're trying to compile to the wrong destination.[*]Sometimes headers will try to import a file that's not actually there; namely NSObject.h. If you get an error that says the compiler couldn't find NSObject.h referenced in so-and-so header, it's not big deal--that header is already imported within the Foundation framework, the compiler's just looking in the wrong place for it even though it's already imported. Delete the #import "NSObject.h" line in the header causing trouble (or comment it out) and it should work fine.[*]If you get warnings/errors about variables not being used/declared/found, take a very close look at your code. A class named FooBar is a completely different class than $FooBar, and a method named doThisThing is completely different than _doThisThing. And yes, some headers like SBApplicationIcon.h have two totally separate methods, setBadge: and _setBadge:, and I couldn't even tell you the difference. But they are different.
Ok so now what
Well, you've got your environment set up now and with a little fiddling around with folder hierarchies, you should be able to compile just about any Mobile Substrate source code available. But what about making your own? Like I said, you'll definitely need to have some object-oriented programming background, and best-case scenario, have already worked with Objective-C and iPhone app development. [ame="http://www.ipodtouchfans.com/forums/showthread.php?t=103558"]Gojohnnyboi has a tiny tutorial[/ame] on starting with Mobile Substrate development. It is quite dated, but it does have some very good information. Ignore all of the stuff about getting the "toolchain" and SpringBoard headers set up (you already did that =] ) and just worry about learning how the code works.
Please let me know RIGHT AWAY if this doesn't work so I can get a fix up right away. Contact me on Twitter @n00neimp0rtant
*Moderators/administration: if there is a legal/copyright problem with sharing the SpringBoard headers, please let me know, and only remove the first link; the second does not contain any SpringBoard headers.
09-23-2010, 07:43 PM #2
Nice bro thanks for that info ! I will try this asap! Do you know if it is possiblle to link a theme with a settings pref? So say I had a weather widget is it possible to make somthing within the codes to have it able toopen in settings and change the weather there? thats an example but I would love to know this it would be epic!
09-26-2010, 06:41 PM #3
Just fixed the guide, I left out a few things. Should be good now.
09-27-2010, 07:53 AM #4
thanks for the update! compiled perfectly this time. Just wondering i go into the folder and see that every .dylib has a .plist where do i obtain that .plist to place into the folder?
could you also give me a site to some nice Mobilesubstrate source code to look at
10-15-2010, 01:57 PM #5
10-23-2010, 04:18 PM #6
Hope u can help. I just tried this tut but didnt work with the example at the end of the post. I did a blank project and did compile and installed it. Does nothing so ...
The error I get when compiling the launch example is that a in file SBIcon.h it has an import "UIView.h" and can not find it. I guess subsequent errors are related to that.
XCode 3.2.3 / 64 bit
10-27-2010, 05:16 PM #7
Am I missing something? Seem to be having the same problem as rsimpsonbusa.
Last edited by dekzter; 10-27-2010 at 05:48 PM.
11-05-2010, 03:22 AM #8
Thanks a lot for taking the time to write up this tutorial, n00neimp0rtant (I'm really looking forward to Open Notifier, btw).
I just had a couple of problems after following this guide for 4.1 and this is how I fixed them. (I don't know if this is the 'right' way to fix them but it seems to work for a simple "Hello, World!" dylib that I did.)
Error 1: UIApplication.h: No such file or directory
1. At the top of SpringBoard.h, remove (or comment out) the #import "UIApplication.h" line.
2. A couple of lines below that (the one that starts with @class NSDate, NSDictionary... etc), add UIApplication to that list. Everything in that line should be separated by a comma and end with a semicolon.
Error 2: Redefinition of 'struct_opaque_pthread_t'
To fix: Still in SpringBoard.h, just comment out the whole struct _opaque_pthread_t section (should be 5 lines).
Again, I'm not sure that this is the best way to do fix these problems so if there's a better way please let me know
I am still getting one warning:
Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'HelloWorld-Info.plist'.
But I don't think it matters much anyway since the .plist isn't even required for the .dylib.
11-11-2010, 04:51 PM #9
After fixing the UIApplication.h and the struct _opaque_pthread_t errors by commenting them out I was still unable to compile. I received the following errors:
1. On line 50 of the .mm file
_SpringBoard$applicationDidFinishLaunching$ = MSHookMessage($SpringBoard, @selector(applicationDidFinishLaunching, &$SpringBoard$applicationDidFinishLaunching$);
The error:invalid conversion from 'void (*)(SpringBoard*, objc_selector*, UIApplication*)' to 'objc_object* (*)(objc_object*, objc_selector*, ...)'
2. On line 16 of substrate.h
void MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix);
The error:too few arguments to function 'void MSHookMessage(objc_class*, objc_selector*, objc_object* (*)(objc_object*, objc_selector*, ...), const char*)'
So you know I'm using I'm compiling to iOS 4.1 and I've made all the necessary adjustments to account for this.
Last edited by DrBeak1; 11-11-2010 at 04:51 PM. Reason: Automerged Doublepost
11-11-2010, 07:38 PM #10
Looks good I hope to try it when I get a vm working
Sent from my iPod touch using ModMyi
03-05-2011, 11:41 PM #11
No good for XCode 4
08-09-2011, 03:36 PM #12
Does it work with Xcode 4.2 and iOS 5 sdk?
Last edited by iGamers; 08-09-2011 at 10:11 PM.
08-09-2011, 10:43 PM #13
Seems that no.
Forget this and use Theos.
08-17-2011, 12:12 AM #14
would theos work on the ios 5 beta sdk and xcode 4.2 beta?
01-20-2012, 05:35 PM #15Linker error.
I'm getting a linker error.
"_main", referenced from:
start in crt1.3.1.o
ld: symbol(s) not found
Am I missing something?