André Fratelli
André Fratelli

Reputation: 6068

Deploying static library in Xcode 6

I want to deploy a static library that I've been writing in Xcode 6. I've already managed to compile the library into a .a file. Now I want to use it in another project. Also, note that including the library project is not an option, as this library is supposed to be distributed in binary.

I also managed to import the .a file into a new project, but I'm not sure what the best way to find the header files is. Should I copy them to a system folder? Should I just link to the framework's (downloaded) folder? Should I import the headers directly in the project? As the framework is meant for distribution, I think that ideally I would copy them to a system folder.

Finally, I've read that I need to build two different versions if I want the framework to be compatible with both iOS and the simulator. Is this true? Can it not be distributed in the same binary?

Upvotes: 0

Views: 486

Answers (1)

David Hoerl
David Hoerl

Reputation: 41652

I distribute such a library for my company. I essentially put the .a file (built up with lipo) into a folder along with the headers. The client then needs to add the .a file to their project in the Build phases, Link Binary With Libraries. Then, they should add the path to the header files using a project relative path to the "User Header Search Paths". From my readme:

Process to Add the SDK to Your Project

1) Copy the xxx folder to the app folder, which contains the ".xcodeproj" project file, then add the directory to your project, but don't add it to any targets (unselect the checkbox). 2) Add the appropriate library (iOS 6.0 or 7.0) folder, by going to your target's Build Phase tab, Link Binary with Libraries, tap on "+", then navigate to the appropriate folder and select libXXX.a

3) Add the following to the Project's Build Settings:

  • Search Paths -> Library Search Paths: $PROJECT_DIR/xxx/ios // I have multiple folders each with a lib
  • Search Paths -> User Header Search Paths: $PROJECT_DIR/xxx
  • Linking -> Other Link Flags: -ObjC NOTE: If you fail to do this, your app will crash on launch (if it uses categories)

I use lipo to add both the Simulator .a files too - even thought this is not officially sanctioned. As others have said, Apple frowns on this yet offers no easy way for users of your library to use different .a files - the "official" solution would be for you to write a custom build script.

Upvotes: 1

Related Questions