Build and use dylib on iOS

來源:互聯網
上載者:User

http://blog.iosplace.com/?p=33

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 “com.apple.product-type.library.dynamic” 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 “com.apple.package-type.mach-o-dylib” 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 “com.apple.product-type.library.dynamic”;

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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.