views:

182

answers:

1

Hello, which is the best approach to include a static library with into an application for iPhone or iPad?

I could choose to

  • compile the library supplying right platform and building a library file with the ar utility and then add as a framework to the project
  • including the source of the library .c/.h and compile them together with the application

The first approach seems simpler, because I won't care about managing all specific settings of the library I want to include but how can I create the library both for iPhone and iPad and allow xcode to use the right library upon linking?

The second approach seems more complex since xcode will take care about compiling my application and the library (with different settings I suppose) then how should I go? I can easily add sources of the lib but I'll have to include the make scripts to allow xcode use them to build in the right way.

Any suggestions about how to proceed? The library I'm trying to include is libssh. (I know that this library, of course, has already been compiled and tried succesfully on iPhone)

Thanks in advance.

+1  A: 

I would go for the first approach.

You should probably build two different versions of your library, one for the iPhone and one for the iPad. These have to be fat libraries containing different architectures (armv6 for iPhone 3G, armv7 for iPhone 3GS, and i386 for the iPhone simulator the first, armv7 and i386 the other one for the iPad).

Basically you build three different versions for the iPhone, then merge them together in a fat file using the lipo tool.

Then, you build again two different versions for the iPad and merge them together using lipo. Note that you can not reuse for the iPad the armv7 and i386 version you compiled originally for the iPhone, because you need to build them using compilers belonging two different SDKs (3.1 for the iPhone, 3.2 for the iPad).

I am not sure if lipo will allow you to merge into a single file two armv7 or two i386 versions of the library without complaining. You may want to try this, because in this case you can come up with just one fat library at the end of the whole process.

unforgiven