Begin main content

Making a fat static library for iOS device and simulator

Some third party iOS library providers (I'm looking at you Omniture) provide separate static library archives for simulator (i386) and device (armv6 and or armv7).

That's a pain since you either change them manually or set the linking flags on different Xcode targets to use the appropriate library (whereas normally with libraries and frameworks you just drag it into your project and you're done).

Instead, you can build your own fat (multi-architecture) library from the provided archives and Xcode will link against the appropriate architecture segment (flagrantly ignoring Erik's dire predictions about testability and your personality ;)

We achieve this using the lipo tool, eg:

lipo -output libOmnitureAppMeasurement-fat.a -create -arch armv6 libOmnitureAppMeasurement-iPhoneDevice.a -arch l386 libOmnitureAppMeasurement-iPhoneSimulator_4_0_GM.a

Update:

The latest Omniture libraries, available via the Omiture SiteCatalyst admin console, now contains armv6 and armv7 architectures. Oddly, that means that they provide two archives—one regular i386 archive (with no fat header) for the simulator and one fat archive for the device with armv6 and armv7 segments. Since the device archive headers now specify the archives already, we don't need to tell lipo anything other than the archive file name.

lipo -output libOmnitureAppMeasurement-fat.a -create libOmnitureAppMeasurement-iPhoneDevice.a -arch i386 libOmnitureAppMeasurement-iPhoneSimulator.a

11:43 PM, 18 Nov 2010 by Mark Aufflick Permalink

Script gor generate for library

Fat library is a good solution, i use it since many month with a script inside my library project. In your project you just need add a simple "shell script target" (you can name it Universal Lib Build). And then in run script script of this target i use the following script (by replacing #variable# by the good) and then the fat library generation i automate:

script :

# shell script goes here

XCODEBUILD_PATH=/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild

SDKROOTDIR=/Users/Shared/_BUILDS_/#LIBRARY_NAME#_SDK

echo "Start Universal #TARGET_NAME# SDK Generation"

echo "Step 1 : #TARGET_NAME# SDK Build Library for simulator and device architecture"

$XCODEBUILD -target "#TARGET_NAME#" -sdk "iphonesimulator" -configuration "Release" clean build 
$XCODEBUILD -target "#TARGET_NAME#" -sdk "iphoneos" -configuration "Release" clean build 

echo "Step 2 : Remove older SDK Directory"

rm -rf $SDKROOTDIR

echo "Step 3 : Create new SDK Directory Version"

mkdir $SDKROOTDIR
mkdir $SDKROOTDIR/build_SDK
mkdir $SDKROOTDIR/build_SDK/headers

echo "Step 4 : Create new SDK binary Version"

cp /Users/Shared/_BUILDS_/Release-iphoneos/#libraryName#.a $SDKROOTDIR/build_SDK
mv $SDKROOTDIR/build_SDK/#libraryName#.a $SDKROOTDIR/build_SDK/#libraryName#_device.a

cp /Users/Shared/_BUILDS_/Release-iphonesimulator/#libraryName#.a $SDKROOTDIR/build_SDK
mv $SDKROOTDIR/build_SDK/#libraryName#.a $SDKROOTDIR/build_SDK/#libraryName#_simulator.a

echo "Step 5 : Create combine lib files for various platforms into one"

# combine lib files for various platforms into one
lipo -create $SDKROOTDIR/build_SDK/#libraryName#_device.a $SDKROOTDIR/build_SDK/#libraryName#_simulator.a  -output $SDKROOTDIR/build_SDK/#libraryName#_SDK.a

echo "Step 6 : Copy headers Needed"
PROJECT_HOME=`pwd`
echo $PROJECT_HOME

cp $PROJECT_HOME/Classes/*.h $SDKROOTDIR/build_SDK/headers

cp $PROJECT_HOME/Classes/#otherDriectoryNeeded#/*.h $SDKROOTDIR/build_SDK/headers

echo "Step 7 : Copy other file needed like bundle"
cp -r $PROJECT_HOME/Classes/*.bundle $SDKROOTDIR/build_SDK/

echo "Step 8 : Create final SDK package"

rm -rf $SDKROOTDIR/#LibraryName#_SDK
mkdir $SDKROOTDIR/#LibraryName#_SDK
cp -r $SDKROOTDIR/build_SDK/headers $SDKROOTDIR/#LibraryName#_SDK
cp -r $SDKROOTDIR/build_SDK/*.bundle $SDKROOTDIR/#LibraryName#_SDK
cp  $SDKROOTDIR/build_SDK/#libraryName#_SDK.a $SDKROOTDIR/#LibraryName#_SDK

echo "Finish Universal #TARGET_NAME# SDK Generation"

exit 0
YD

by Unregistered Visitor on 10/06/11

Nice post

Guar protein offer a wide selection of products for your specific requirements.
Guar korma exporter

by Unregistered Visitor on 09/17/14

Add comment