Build and use dylib on iOS

October 1st, 2010

Xcode does not allow you to build dylib for iOS. App will be rejected if it’s not single binary. But I have an application that has plug-in architecture to load optional modules. I just want a quick prototype to prove concept before fully port it to iOS. It’s faster to do if dylib could simply work. So, this post shows how to build and use dylib but be aware it won’t be approved to App Store. (Tested with Xcode 3.2.4 on 10.6.4)

1. Open these files in the Property List Editor: “/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Specifications/MacOSX Product Types.xcspec” and “/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Specifications/iPhone Simulator ProductTypes.xcspec”

2. Locate the item in the “MacOSX Product Types.xcspec” that has the product type “” and drag it to the “iPhone Simulator ProductTypes.xcspec”.

3. Open “MacOSX Package Types.xcspec” and “iPhone Simulator PackageTypes.xcspec” found at the same places.

4. Locate the item in the “MacOSX Product Types.xcspec” that has the package type “” and drag it to the “iPhone Simulator PackageTypes.xcspec”.

5. Repeat the steps for the “iPhoneOS.platform” and relaunch Xcode if it was running.

Now, lets build a dylib. Start out with the “Cocoa Touch Static Library” Templete. That should included the Foundation.framework in the project. Here are the changes I made on top of the templete to build dylib.

1. Open the file “project.pbxproj” (found inside the Xcode project file bundle) in a Text Editor. Search for string “producttype”, change it’s value to “”;

Now, open the project with Xcode, go to Project->Edit Project Settings

2. “Installation Directory” set to @executable_path/ because I plan to put the dylib in the same directory as the app’s executable.

2. “Mach-O Type” set to Dynamic Library

3. “Executable Extension” set to dylib

4. “Executable Prefix” set to empty

5. Add one or two simple methods to the library and build it.

Now, create an app to test it. This time, I choose the “View-based Application”. Hook up a UIButton and a UILable to call the lib and showing return message. You can download the complete project TestApp and play with it.

17 Responses to “Build and use dylib on iOS”

  1. Ken says:

    Many thanks for these posts..they’re brilliant.

    Can an app with dylib or a libmysqlclient.a inluded still be submitted to the App Store for acceptance?


  2. .:M_F:. says:

    Hi! =) Thanks a lot for the tutorial!!
    If I would submit my app to the App Store, third library aren’t allowed…is there an other method to include all class of mySQL connection to my project?

    Sorry for my bad english :(

  3. Wei says:

    You can use the mySql static library.

  4. ray says:

    So apple officially reject any apps that uses non-buildin dylib, right?

    If I include a dylib that I build, I will be rejected?


  5. Wei says:


  6. Silvano says:

    How is the correct type of use mysql from iPad (The way that Apple do not reject)?

  7. Wei says:

    Build a static library instead.

  8. matalaz says:

    A quick question: the dylib must be signed?

  9. newuser says:

    This is perfect , was really helpful …saved me lot of research time

  10. Nate says:

    Great work. Same technique works for XCode 4. Helpful for building jailbreak apps and SBSettings toggles.

  11. [...] Build and use dylib on iOS « iOS Place. Like this:LikeBe the first to like this. This entry was posted in IOS. Bookmark the permalink. ← Debugger Visualizers for C++ in Visual Studio 2012 [...]

  12. [...] Build and use dylib on iOS. [...]

  13. selvakumar says:

    I did the same steps mentioned above. I tried to run the sample app provided it throws the following error.

    ld: can’t open output file for writing: /Users/admin/Library/Developer/Xcode/DerivedData/TestLib-fkarkpnkpbyjjyeavehukqrpkwsk/Build/Products/Debug-iphoneos/, errno=2 for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    What should i do to resolve this issue.


  14. Craig Newell says:

    selvakumar: With Xcode 4.5 DP3, I had to take entries from both the Product and Package files and then remove the CODE_SIGNING_ALLOWED from the iPhoneSimulator project changes as that does not support code signing.

  15. [...] Setup dylib compiling for iOS from XCode from the instructions at “Build and use dylib on iOS” by iOS Place. [...]

  16. Krishnendra says:

    I have following error :(
    target specifies product type ‘’, but there’s no such product type for the ‘iphoneos’ platform .

  17. Jean-Claude says:

    How did you ever figure all this out? Yer a wizard, Harry.
    Thank you very much, it’s a fine bit of detective work you must have done to decipher all this.
    What a shame about the no-dynamic-libs policy in the Apple store, they should let an application load its own plug-ins.
    What’s to stop someone from changing the filename and including the lib as an asset?
    Thanks again.

RSS feed for comments on this post. And trackBack URL.

Leave a Reply