Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fat libraries in XCode 5

I've been trying to build a static library and then create a binding project from it in Xamarin. Everything was working fine until iOS 7 hit. I had to grab the latest version of the native library and try and build it in XCode 5, but it's been giving me all kinds of problems. I think it might be related to the build process or possibly some changed setting in XCode 5 (vs. 4) but I'm not sure.

I was using this script to build a universal binary which is based of work in this question:

Build fat static library (device + simulator) using Xcode and SDK 4+

One thing I did notice is that previous, in the old iOS 6.1 version of my binary (built in XCode 4), my binary was about 24 Mb, now with XCode 5 it's ballooned to almost 50 Mb! Which is leading me to think that there is something wrong with the compiling and linking step.

Any ideas? Has anybody else encountered problems with universal binaries in XCode 5 (vs 4)?

like image 344
Matt Burland Avatar asked Sep 25 '13 16:09

Matt Burland


People also ask

What is a fat library?

A fat library is simply a library with multiple architectures. In our case it will contain x86 and arm architectures. The proper name is 'Universal Static Library'.

Is XCFramework dynamic or static?

An XCFramework can be either static or dynamic and can include headers.

What are dynamic libraries in Swift?

Dynamic library - a unit of code and/or assets linked at runtime that may change. However, only Apple is allowed to create dynamic libraries for iOS . You're not allowed to create these, as this will get your app rejected.

How do I use XCFramework?

To use the . xcframework output simply add it as embedded content to a specific target and Xcode will use the correct binaries for the corresponding platform. It's that easy — you now just need to add import Framis or import FramisTouch into a source code and use the module as usual.


2 Answers

I'm using the makefile below for my library and it works flawless even with XCode 5 and the iOS7 SDK.

XBUILD=/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
PROJECT_ROOT=.
PROJECT=$(PROJECT_ROOT)/GIFLibFrontEnd.xcodeproj
TARGET=GIFLibFrontEnd

all: libUniversal.a

libi386.a:
    $(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -configuration Release clean build
    -mv $(PROJECT_ROOT)/build/Release-iphonesimulator/lib$(TARGET).a $@

libArmv7.a:
    $(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch armv7 -configuration Release clean build
    -mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $@

libArmv7s.a:
    $(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch armv7s -configuration Release clean build
    -mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $@

libArm64.a:
    $(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphoneos -arch arm64 -configuration Release clean build
    -mv $(PROJECT_ROOT)/build/Release-iphoneos/lib$(TARGET).a $@

libUniversal.a: libi386.a libArmv7.a libArmv7s.a libArm64.a
    lipo -create -output lib$(TARGET)Universal.a $^

clean:
    -rm -f *.a *.dll
    -rm -rf build
like image 93
Oliver Weichhold Avatar answered Oct 08 '22 14:10

Oliver Weichhold


Here's a link to a Makefile with the tabs, and I made a little change to separate out the target name from the library name. Thanks very much for this! This solved my problem!

like image 29
Chris Prince Avatar answered Oct 08 '22 15:10

Chris Prince