I have a bash script that builds my iOS static library for both ARM and i386 architectures. I am then using lipo to combine the binaries into a single "combined" library so that it can be linked to in the simulator as well as on a device. For some reason when I attempt to link against the resulting fat library I still get linker errors complaining that symbols are not found for i386 when debugging. I'm wondering if I am not building the simulator or iphoneos libraries correctly before using lipo. Can someone help me out?
Here is my bash script:
if [ $1 == "clean" ]
then
echo -e "Perform Clean\n"
if [ -d build ]
then
rm -r build
exit
fi
else
echo -e "Begin combined build process.\n"
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
echo -e "xcode build executable path: $XCODEBUILD\nBuiding i386 static library.\n"
$XCODEBUILD -project MyLibrary.xcodeproj -target "MyLibrary" -sdk "iphonesimulator" -configuration "Release" clean build
echo -e "Buiding ARM static library.\n"
$XCODEBUILD -project MyLibrary.xcodeproj -target "MyLibrary" -sdk "iphoneos" -configuration "Release" clean build
echo -e "Combine ARM and i386 libs.\nOutput: build/combined/libMyLibrary.a\n"
[ -d build/Release-combined ] || mkdir build/Release-combined
lipo -create -output "build/Release-combined/libMyLibrary.a" "build/Release-iphoneos/libMyLibrary.a" "build/Release-iphonesimulator/libMyLibrary.a"
echo -e "Done!\n"
fi
exit
When I add link against the resulting lib "build/Release-combined/libMyLibrary.a". I get linking issues. Am I doing something wrong?
Thanks!
Well there are 2 ways to make gcc/clang build a different arch.
you can pass the
-m32
or-m64
flag...but it is more explicit to use the
-arch x86_64 -arch i386
flags which in apple clang and apple gcc can be passed at the same time.