3

I have a third party iOS library that links and runs fine in my app and in the simulator. I am trying to extract the object files from it in order to integrate it with another piece of third party software that repackages the object files with their own code. However, I am unable to extract the object files via ar; I consistently get the error, "Inappropriate file type or format".

The library in question is a fat library with armv7, armv7s, and i386 included. Stock lipo doesn't know about armv7s on my machine, but Xcode's does:

$ lipo -info library.a
Architectures in the fat file: library.a are: armv7 (cputype (12) cpusubtype (11)) i386 
$ xcrun -sdk iphoneos lipo -info library.a 
Architectures in the fat file: library.a are: armv7 armv7s i386 

I can successfully thin it out with lipo:

$ xcrun -sdk iphoneos lipo library.a -thin armv7 -output library-armv7.a
$ xcrun -sdk iphoneos lipo -info library-armv7.a 
Non-fat file: library-armv7.a is architecture: armv7

However, even after thinning it out, I can't manipulate it with ar:

$ xcrun -sdk iphoneos ar -tv library-armv7.a 
ar: library-armv7.a: Inappropriate file type or format
$ xcrun -sdk iphoneos ar -xv library-armv7.a 
ar: library-armv7.a: Inappropriate file type or format

I'm on OS X 10.8.2, Xcode 4.6 with development tools installed.

Is there any additional step I can take for this troublesome library?

Update in response to Martin's comment

file shows the following:

$ file library.a
library.a: Mach-O universal binary with 3 architectures
library.a (for architecture armv7): Mach-O object arm
library.a (for architecture cputype (12) cpusubtype (11)):  Mach-O object arm
library.a (for architecture i386):  Mach-O object i386
$ file library-armv7.a 
library-armv7.a: Mach-O object arm

Looks like it's not a library at all!

Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
  • 1
    What does the "file" command print for your archive? – Martin R Mar 13 '13 at 19:06
  • Huh. The "library" delivered is actually an object already... That might negate all of this. – Ian Terrell Mar 13 '13 at 19:21
  • How about using extract instead of thin on lipo? I've never used the thin command - I don't think it's doing what you want. – escrafford Mar 13 '13 at 19:25
  • extract actually keeps it as a fat library, but with only the one architecture. ar only works on single-architecture libraries, to the best of my knowledge. I think Martin got me sorted out with the suggestion to examine it via file – Ian Terrell Mar 13 '13 at 19:37

2 Answers2

1

The "library" is not actually a library, but is an object file itself. There is nothing further to extract.

Ian Terrell
  • 10,667
  • 11
  • 45
  • 66
0

This script works well. Try it.

https://code.google.com/p/ompt-intel-openmp/source/browse/itt/libomp_oss/tools/extract-objects.pl

tacke
  • 145
  • 1
  • 5