I’ve created an Xcode 4 project template to create universal (armv6, armv7 and simulator) static libraries for iOS, based on [Adam Martin’s script](http://red-glasses.com/index.php/tutorials/xcode4-make-a-library-in-one-file-that-works-on-both-device-and-simulator/comment-page-1/#comment-2226):
[iOS-Universal-Library-Template](https://github.com/michaeltyson/iOS-Universal-Library-Template)
The existing static library template provided with Xcode only builds one architecture, which is not particularly suitable for distribution. A number of people have created scripts to create universal libraries, which require some mucking around with Xcode target settings to use.
This template draws on this work to provide all that is required to produce universal libraries – just select the ‘Universal Static Library’ type in the New Project/New Target dialog, and you’re all set.
Hi Michael,
Afraid it’s not working for me. I’m getting: warning: ignoring file ~/libHRVKit.a, missing required architecture i386 in file
When trying to link against the created library. Any suggestions?
–Alex
Hey Alex – it sounds like you’re grabbing the lib from the wrong architecture; when you build, there’ll be three different folders showing up in the built products dir (accessible by right-clicking the product and hitting ‘Show in Finder’) – [Debug/Release]-iphoneos, -iphonesimulator, and -universal. You wanna grab the built library from the ‘universal’ folder.
Hmm… I was gonna say I’ll update the documentation to be clearer about that, but maybe it’d be more obvious to just copy the universal build to the other folders! I’ll do that instead.
Ah thanks very much. I was a) being stupid, b) seemed to have made a series of compounding mistakes that got XCode in quite a twist. One quick followup question. I don’t think it’s possible, but might as well make sure. Is there any way I can bundle a resource inside the static library? Even if the library itself is the only thing that will use it, ie. it doesn’t need to be available to external projects?
Thanks for the quick turnaround.
–Alex
Cool =)
Yeah, sure – take a look at xxd (
xxd -i {infile} > {outfile.c}
)