Compiling static library for Unity 4.6.3 (64-bit & IL2CPP) - ios

I have a static library that I've been integrating into my Unity-iOS projects for several months now. Everything has been working fine for Unity 4.3.x.
With the recent release of Unity 4.6.3, which provides building for 64-bit devices using the IL2CPP scripting backend and Universal architecture, my static library no longer works. I have a built a very simple sample app with Unity using just the static library and it crashes at runtime.
SDKTestApp(11555,0x199dff310) malloc: *** error for object 0x174287f2f: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
Note that the project compiles just fine, but shortly after the app loads and some static library functions are executed, it crashes. And this is only problematic with those devices that are 64-bit only (iPhone 6, iPad Air, etc.).
Finally, here is the output when I run lipo -info myStaticLibrary.a on the (.a) file:
myStaticLibrary.a: Mach-O universal binary with 3 architectures
myStaticLibrary.a (for architecture arm64): current ar archive random library
myStaticLibrary.a (for architecture armv7s): current ar archive random library
myStaticLibrary.a (for architecture armv7): current ar archive random library
Any ideas?

Turns out it had nothing to do with my Xcode settings, and in fact, my Xcode settings were correct. This was a bug related to my specific code.
For future reference, the lipo -info myStaticLib.a is incredibly useful to determining architecture support.

Related

How to enable 64-bit support with GPUImage

When building app with GPUImage, I got errors like this
ld: warning: directory not found for option '-L/Users/.../GPUImage'
ld: warning: ignoring file /Users/.../Libraries/GPUImage/libGPUImage.a, missing required architecture x86_64 in file /Users/.../Libraries/GPUImage/libGPUImage.a (3 slices)
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_GPUImageCrosshatchFilter", referenced from:
objc-class-ref in AddPopViewController.o
I don't know if this error is related, but what I want to do is for my app to support 64-bit processors. How can I do that?
In this link, it says
The framework supports 64-bit, but you'll have to enable this for your project in the framework and your application yourself
How do I do this? Thanks
Following are the steps given in the iOS documentation to ensure the app supports 64 bit. Check if the following points are taken care in your environment.
At a high level, here are the steps to create an app that targets both the 32-bit and the 64-bit runtime environments:
Install the latest Xcode.
Open your project. Xcode prompts you to modernize your project. Modernizing the project adds new warnings and errors that are
important when compiling your app for 64-bit.
Update your project settings to support iOS 5.1.1 or later. You can’t build a 64-bit project if it targets an iOS version earlier than
iOS 5.1.
Change the Architectures build setting in your project to "Standard Architectures (including 64-bit)."
Update your app to support the 64-bit runtime environment. The new compiler warnings and errors will help guide you through this
process. However, the compiler doesn’t do all of the work for you; use
the information in this document to help guide you through
investigating your own code.
Test your app on actual 64-bit hardware. iOS Simulator can also be helpful during development, but some changes, such as the function
calling conventions, are visible only when your app is running on a
device.

Fat binary validation - (Cocoa [Touch Framework] / [Static Library (converted to framework)]

.
Hello, all.
I noticed some strange thing.
As all you know there are a lot of complaints regarding "unsupported architecture" error message during validation against App Store when using 3rd party frameworks with i386 slice (for example).
I've upgraded xCode to 6.2 and now I have following situation:
I built some simple Single-View application (iPhone) that's using two external custom frameworks (that I built too).
One of the frameworks is 'Cocoa Touch Static Library" that was converted to the framework (using custom script) with two '.a' files (iphoneos and iphonesimulator configurations) combined into one fat binary (using lipo).
The second framework is "Cocoa Touch Framework" (actually, its static version - via Mach-O build settings), with two binary frameworks combined to one fat binary (using lipo too).
When I check both contained-in-framework binaries with "lipo -info" I get - "armv7 i386 x86_64 arm64" in case of first framework and "i386 x86_64 armv7 armv7s arm64" in case of the second one (second framework was built intentionally (manually) with these architectures).
When I archive my app and try to validate it from Organizer - it passes successfully.
When I check the application binary (from the xCode archive folder) with "lipo -info" I get "armv7 arm64" - so now it's clear why no error message is displayed during app validation.
Have any of you seen such behavior?
May Apple fix this issue in xCode 6.2?
I'm going to test it tomorrow with old xCode version (6.1.1) anyway.
Any input is more than welcomed.
Thank you.

Linking to Google APIs Objective-C Client Library as iOS static library

I have so far used Google APIs Client Library for Objective-C by compiling the source files directly into my app (as described here). If I were to switch over to linking to the iOS static library (as also described here), how would this insure that the code works on different architectures?
For instance, if I follow the verbatim instruction I have to compile the static library by choosing a schema (GTLTouchStaticLib) and an architecture (e.g. iOS Simulator: iPhone 5). If I choose a simulator as architecture, file libGTLTouchStaticLib.a reports that the archive contains code for architectures i386 and x86_64. If I choose a physical iPhone 5 instead, file reports on architectures armv7 and arm64.
How do I ensure that the libGTLTouchStaticLib.a that I'm going to drag into my application project's Build Phases "Link Binary with Libraries" list (according to Google's instructions) contains all (not just some) of the architectures that might be encountered when my app goes life? I guess armv7 and arm64 is sufficient for an app that requires iOS 8, but I'd like to be sure.)
You have to combine the generated binaries using lipo command line tool.
The following tutorial about creating static library in iOS demonstrates use of lipo under section Universal Binaries

using lipo vs "valid architecture" while creating universal static library

I want to create a universal static library, say called sampleStaticLib.a, which gets included in an app called HelloWorld. The HelloWorld app needs to use the APIs defined in the static library, and needs to work on both iOS simulator and iOS device. I understand from various posts in the Internet that I can accomplish this by using the lipo tool to aggregate the static libraries of both the simulator and device into a universal library, and then include the universal library inside the HelloWorld.xcodeproj.
However, alternatively, if I do the following:
simply set the valid architecture in the static library xcodeproject
(sampleStaticLib.xcodeproj) to "armv7 armv7s arm64 i386 x86_64
generate the sampleStaticLibrary.a
include it in the HelloWorld.xcodeproj
My expectation is that, since I set the valid architecture of 'sampleStaticLib' to all architectures spanning x86 and ARM, the library should work on both simulator and device. But it doesn't work on the simulator.
So, can't setting a broad "valid architecture" replace the need to use 'lipo tool' while creating universal static libraries?
No, unfortunately, that is not possible as trivially as you would like.
The reason is that when you build your project, it will build with the selected SDK for all of the requested architectures. The iOS SDK supports ARM, and the iOS Simulator SDK supports Intel. You need to build the ARM slices against the iOS SDK and the Intel slices against the iOS Simulator SDK and then lipo them together into a universal binary.
It should work. For instance, this static library
https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin/blob/v3/png/prebuilt/ios/libpng.a
It has armv7, armv7s, arm64, i386 and x86_64 binaries.
$ file libpng.a
libpng.a: Mach-O universal binary with 5 architectures
libpng.a (for architecture armv7): current ar archive random library
libpng.a (for architecture armv7s): current ar archive random library
libpng.a (for architecture i386): current ar archive random library
libpng.a (for architecture x86_64): current ar archive random library
libpng.a (for architecture cputype (16777228) cpusubtype (0)): current ar archive random library <-- It's arm64
Xcode(Clang toolchain) can link this static library for iOS device and also iOS simulator. And no problems at all.
But it doesn't work on the simulator.
What do you mean? I recommend you to update the question about it more detail.

How to ignore ld warning about missing i386 architecture for device-only framework

My app employes an external device (hardware accessory). I'm using a framework provided by the hardware supplier, but this only runs on the device (they do no support running in the simulator). Because of this, I'm getting the following warning when I compile:
ld: warning: ignoring file ...xxx.a, missing required architecture i386 in file
...xxx.a (2 slices)
Is there any way to tune my project configuration so that I no longer get this error when building for the simulator? I know it's a cosmetic issue, but I'd rather have my build log clean when I have no (real) problems in my code.
In the project setting, it's possible to add different libraries according to the current configuration and/or the os. Thus you can add your library only if your building for a real an iOS SDK (and not for the iOS simulator SDK).

Resources