+ Reply
Results 1 to 15 of 15

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: [TUTORIAL] How To Compile Mobile Substrate Extension in Xcode

is a discussion within the

iPhone / iPod Touch SDK | Development Discussion

forums, a part of the

3rd Party Apps For iPhone | iPod Touch

section;
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
...
  1. #1
    Developer n00neimp0rtant's Avatar
    Join Date
    Feb 2008
    Location
    Pittsburgh, PA
    Posts
    1,341
    Thanks
    25
    Thanked 600 Times in 136 Posts

    Default [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
    1. 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)*
    2. 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)
    3. 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)
    4. Move the entire "Mobile Substrate Extension" folder into ../Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/
    5. Move libsubstrate.dylib into ../Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/
    6. Open up Xcode and start a new project using the Mobile Substrate Extension template
    7. Make sure you change from Simulator to Device or it will give all sorts of missing file errors
    8. 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:
    1. In Finder, open up your project folder
    2. Go into the build folder and then into either the Release-iphoneos or Debug-iphoneos folder, depending on which settings you used to compile
    3. 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
    4. There will be a file in there with the same name as your project and no file extension; copy it to some other place
    5. Add the extension ".dylib" to the file
    6. Copy that file to /Library/MobileSubstrate/DynamicLibraries/ on your iPhone using an iPhone browser or SSH
    7. 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:
    1. In the menu bar, click Project > Edit Project Settings
    2. Click the "Build" tab at the top
    3. Drop down the Configuration box and change it to Debug
    4. Change the Base SDK to iPhone Device 4.0
    5. Drop down the Configuration box and change it to Release
    6. Change the Base SDK to iPhone Device 4.0
    7. Close the window
    8. Expand the Frameworks folder in the sidebar to reveal the red Foundation and UIKit frameworks, then delete them both
    9. Control-click the Frameworks folder > Add > Existing Frameworks...
    10. Choose Foundation and UIKit from the list
    Again, you only have to worry about this if you are NOT using the 4.0 SDK. Most of the time, small revisions like 4.0 > 4.1 will not have much effect on MS extension compatibility, but you can never be too safe, right?

    Omfg errors

    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.

  2. The Following 3 Users Say Thank You to n00neimp0rtant For This Useful Post:

    FreeApple (09-23-2010), lenny_xenicus (11-05-2010), Liran Z (01-26-2013)

  3. #2
    Master Theme Creator FreeApple's Avatar
    Join Date
    Mar 2010
    Location
    Lake George, NY
    Posts
    1,085
    Thanks
    1,328
    Thanked 1,049 Times in 414 Posts

    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!

  4. #3
    Developer n00neimp0rtant's Avatar
    Join Date
    Feb 2008
    Location
    Pittsburgh, PA
    Posts
    1,341
    Thanks
    25
    Thanked 600 Times in 136 Posts

    Just fixed the guide, I left out a few things. Should be good now.

  5. #4
    What's Jailbreak? waste str's Avatar
    Join Date
    Nov 2009
    Location
    New Zealand
    Posts
    23
    Thanks
    2
    Thanked 11 Times in 9 Posts

    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

    thanks

  6. #5
    Developer n00neimp0rtant's Avatar
    Join Date
    Feb 2008
    Location
    Pittsburgh, PA
    Posts
    1,341
    Thanks
    25
    Thanked 600 Times in 136 Posts

    Just updated again with a little section on errors lol

  7. #6
    What's Jailbreak?
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

    Thanks

  8. #7
    What's Jailbreak?
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Quote Originally Posted by n00neimp0rtant View Post


    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:[LIST=1][*]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
    I'm having troubles adapting this to use the SpringBoard hook used in the other link. When I'm building I'm running into UIView.h No Such File or Directory. I've set everything to 4.1, then added the frameworks Foundation and UIKit, they are not red. If I'm using 4.1 do I need to set the Base SDK to a MISSING iPhone Device 4.0? I've class-dump'ed the 4.1 using class-dump 3.3.3 and placed them in the 4.1 sdk include directory.

    Am I missing something? Seem to be having the same problem as rsimpsonbusa.
    Last edited by dekzter; 10-27-2010 at 05:48 PM.

  9. #8
    What's Jailbreak?
    Join Date
    Sep 2007
    Posts
    13
    Thanks
    5
    Thanked 1 Time in 1 Post
    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
    To fix:
    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.

  10. #9
    What's Jailbreak?
    Join Date
    Oct 2010
    Location
    Sunnyvale, CA
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    PLEASE HELP!!

    Quote Originally Posted by DrBeak1 View Post
    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$ = MSHookMessage(, @selector(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.

    PLEASE HELP!!
    Cool, got it-- As I was searching around I realized that my substrate.h file was missing a (NULL) on line 16 after *prefix. Weird, how did I get a bunk substrate file?
    Last edited by DrBeak1; 11-11-2010 at 04:51 PM. Reason: Automerged Doublepost

  11. #10
    What's Jailbreak?
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    0
    Thanked 1 Time in 1 Post
    Looks good I hope to try it when I get a vm working


    Sent from my iPod touch using ModMyi

  12. #11
    Green Apple app0's Avatar
    Join Date
    Feb 2010
    Location
    Russia, Ufa
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts

    No good for XCode 4

  13. #12
    iPhoneaholic iGamers's Avatar
    Join Date
    Jun 2011
    Location
    Riverside, California, United States
    Posts
    479
    Thanks
    24
    Thanked 81 Times in 61 Posts

    Does it work with Xcode 4.2 and iOS 5 sdk?
    Last edited by iGamers; 08-09-2011 at 10:11 PM.

  14. #13
    Green Apple app0's Avatar
    Join Date
    Feb 2010
    Location
    Russia, Ufa
    Posts
    36
    Thanks
    2
    Thanked 3 Times in 3 Posts

    Seems that no.
    Forget this and use Theos.

  15. #14
    iPhoneaholic iGamers's Avatar
    Join Date
    Jun 2011
    Location
    Riverside, California, United States
    Posts
    479
    Thanks
    24
    Thanked 81 Times in 61 Posts

    would theos work on the ios 5 beta sdk and xcode 4.2 beta?

  16. #15
    What's Jailbreak?
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Linker error.
    I'm getting a linker error.

    Undefined symbols:
    "_main", referenced from:
    start in crt1.3.1.o
    ld: symbol(s) not found

    Am I missing something?

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts