iOS: Compiling Static Libraries

1.4k Views Asked by At

I'm trying to build my first static library and i'm having a compile problem. I mean I can compile my library and every thing looks fine, but when I set up a test project to test it I got this kind of error:

ld: warning: ignoring file /Users/*/Desktop/TestApp/LibProva/libProva.a, file was built for archive which is not the architecture being linked (i386) Undefined symbols for architecture i386: "_OBJC_CLASS_$_Prova", referenced from: objc-class-ref in AppDelegate.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

ld: warning: ignoring file /Users/**/Desktop/TestApp/LibProva/libProva.a, file was built for archive which is not the architecture being linked (i386)

So I guess thats something wrong with compiling (due to different architectures in simulator and in device), but I can not find out how to do it the right way. Can someone explain me how to solve this problem?

1

There are 1 best solutions below

0
On

You must use lipo to create a universal binary:

#!/bin/bash
#build the device
echo building for ARM architecture
xcodebuild -sdk iphoneos4.3 "ARCHS=armv6 armv7" build > /dev/null
#build the simulator
echo building for the i386 architecture
xcodebuild -sdk iphonesimulator4.3 "ARCHS=i386 x86_64" "VALID_ARCHS=i386 x86_64" build > /dev/null
#make the folder
mkdir "Fat Binary"
#lipo suck it together
echo lipo binaries together
lipo -output Fat\ Binary/libmylib.a  -create build/Release-iphoneos/libprefuse_visual_iOS.a build/Release-iphonesimulator/libmylib.a
echo lipo binary saved at $./Fat Binary/libmylib.a
echo copying headers
cp -R build/Release-iphoneos/usr "Fat Binary"
echo [COMPLETE]

Be sure to replace instances of libmylib.a with the actual name of the .a generated by xcodebuild.