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

Edu

Institutes ought to keep in view the monetary conditions from the learners. They should be hard college essay writing service grab essays throughout using high priced expenses or perhaps school fee.

by Unregistered Visitor on 02/18/15

Nice

This is my first time go to see at here and i am genuinely pleasant to read everything at one place. Reality Porn Tube

by Denell Eposey on 02/18/15

ragahv

An appropriate completely did watch acted this kernel besides essence of the sire. We pick finally hardly neglect this friendly of stroke regarding kindness. cccam server

by Unregistered Visitor on 02/19/15

good job

choose the best holi images, sms, wallpapers from our beautiful collection and share with friends on whatapp, facebook,twiiter and other social media holi whatsapp messages

by koppadi nani on 02/25/15

website

Help Making Mobile Phone Apps Here It looks like I am raking in money now, but the truth is that it was not always like that! Just 6 months ago I was completely struggling. I had no programming skills, no team and no money. The only thing I had was a great desire to create the game of my dreams. http://03dd4gqsm6tr0yebio1bnhhsxg.hop.clickbank.net/?tid=PHXDAN ...

by Unregistered Visitor on 02/26/15

wdw

Emulatore xBox 360La corte ha sentito diversi partecipanti frode Kippax piramidale. Questi dovrebbero "investire" tra $ 3200 e $ 3600 e le loro ricompense monetarie sono stati promessi se hanno reclutato altri investitori. xBox 360 Emulatore

by Unregistered Visitor on 02/26/15

Add comment