views:

66

answers:

1

When I get a 3rd party static library, I can use it in my debug or release builds for both the simulator and device. However, when I build locally, it is targeted for debug simulator/device or the same for release. I then have to coordinate my host app to match the library build. How can I create a single static library build that works with all build versions of the host app like many 3rd party static libraries do?

+1  A: 

I don't think there's a "magical" solution for the iPhone for this. I once looked for the same thing didn't find any "easy to use" solution. Best I could find : http://www.clintharris.net/2009/iphone-app-shared-libraries/ Especially the part regarding "Fat libraries", that refers to http://latenitesoft.blogspot.com/2008/10/iphone-programming-tips-building-unix.html But the MAKE configuration doesn't look easy (at least for me).

The way I do it : I build the static libs separately for all configurations I need (simulator x86 debug, and device arm debug for instance). This gives me two different .a files. I renamed them mylibrary_arm.a and mylibrary_x86.a

Then, for any project that wants to use those 2 libraries, I drag and drop THE TWO .a FILES into the client project that needs the .a library + the .h headers that will enable the use of those libraries. Then, when I choose simulator or device in this client project, the compiler chooses the right .a AUTOMATICALLY to compile and run properly .

So in the end, the only boring phasis is the generation of the .a themselves, but the use of them is quite easy and XCode adjusts itself automatically.

yonel
Ok, good idea. I'm guessing the resulting .app file will only include the .a file that corresponds to its build?
4thSpace
as this is a static link, you don't really see the resulting .a in the .app file (one single executable is generated for the current selected target).But if I look at the generated binary size, it looks quite correct = no useless executable code seems to be embedded into this binary.
yonel
Do you create debug/release versions for the simulator and also for the device and end up with four versions of library files in the host project? I noticed Xcode doesn't complain if you have two of the same file names in a project - mylib_debug.a for simulator and device.
4thSpace
For the release / debug I couldn't say, I didn't do it in practice. But for the device / simulator (I was always building in debug): XCode doesn't complain and takes the right one to build. I would expect it to do the same for the release / debug and take the right one ..... :/
yonel