Build fat static library (device + simulator) usin

2018-12-31 05:29发布

It appears that we can - theoretically - build a single static library that includes both simulator and iPhone and iPad.

However, Apple has no documentation on this that I can find, and Xcode's default templates are NOT configured to do this.

I'm looking for a simple, portable, re-usable technique that can be done inside Xcode.

Some history:

  • In 2008, we used to be able to make single static-libs that included both sim and device. Apple disabled that.
  • Throughout 2009, we made pairs of static libs - one for sim, one for device. Apple has now disabled that too.

References:

  1. This is a great idea, it's an excellent approach, but it doesn't work: http://www.drobnik.com/touch/2010/04/universal-static-libraries/

    • There's some bugs in his script that means it only works on his machine - he should be using BUILT_PRODUCTS_DIR and/or BUILD_DIR instead of "guesstimating" them)
    • Apple's latest Xcode prevents you from doing what he's done - it simply will not work, due to the (Documented) change in how Xcode processes targets)
  2. Another SO questioner asked how to do it WITHOUT xcode, and with responses that focussed on the arm6 vs arm7 part - but ignored the i386 part: How do i compile a static library (fat) for armv6, armv7 and i386

    • Since Apple's latest changes, the Simulator part isn't the same as the arm6/arm7 difference any more - it's a different problem, see above)

标签: iphone xcode
9条回答
像晚风撩人
2楼-- · 2018-12-31 06:08

I've made this into an Xcode 4 template, in the same vein as Karl's static framework template.

I found that building static frameworks (instead of plain static libraries) was causing random crashes with LLVM, due to an apparent linker bug - so, I guess static libraries are still useful!

查看更多
ら面具成の殇う
3楼-- · 2018-12-31 06:10

I've made an XCode 4 project template that lets you make a universal framework as easily as making a regular library.

查看更多
只若初见
4楼-- · 2018-12-31 06:11

I needed a fat static lib for JsonKit so created a static lib project in Xcode and then ran this bash script in the project directory. So long as you've configured the xcode project with "Build active configuration only" turned off, you should get all architectures in one lib.

#!/bin/bash
xcodebuild -sdk iphoneos
xcodebuild -sdk iphonesimulator
lipo -create -output libJsonKit.a build/Release-iphoneos/libJsonKit.a build/Release-iphonesimulator/libJsonKit.a
查看更多
登录 后发表回答