15

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)?

Community
  • 1
  • 1
Matt Burland
  • 44,552
  • 18
  • 99
  • 171

1 Answers1

23

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
hb.
  • 1,705
  • 5
  • 22
  • 43
Oliver Weichhold
  • 10,259
  • 5
  • 45
  • 87
  • 1
    Please forgive my ignorance of XCode (which is why I use Xamarin) but how do I set up a make file? The script I was using I'd just added to "build phases" in my XCode project. Is this similar? Or is there some other trick to using this? – Matt Burland Sep 26 '13 at 14:30
  • You should be able to drop the my makefile directly into your library project folder and adjust the PROJECT and TARGET variables to match your project and be good to go. I mean just create a file "makefile" and paste the contents of my makefile and adjust. – Oliver Weichhold Sep 26 '13 at 14:37
  • And dont forget to run "make" afterwards :) – Oliver Weichhold Sep 26 '13 at 14:41
  • Ohh and by the way. You need to have installed the XCode Command Line tools for this to work. You can install them from XCode -> Preferences -> Downloads. – Oliver Weichhold Sep 26 '13 at 14:43
  • Ok - I got the make file working and it looks like it compiles the universal binary. Unfortunately, it doesn't fix the crashing problem I'm having with the library, but I'm pretty confident now that the problem is coming from somewhere else. But thanks for all your help. – Matt Burland Sep 26 '13 at 15:27
  • 1
    If you are getting a "Missing Separator" error, it's most likely because you need tab characters instead of spaces in your makefile. – Chuck Pinkert Feb 13 '14 at 21:00
  • I'm having a problem where this script goes into an infinite loop building only the iphonesimulator line. I fixed the Missing Separator issue... I put tabs on each line that's indented. – Paul Reedy Feb 18 '14 at 22:44