41

I want to build a static library for iphone. I want to give my users the .a library which they can use for both simulator test and device test. Do I have to build two library in simulator mode and device mode? Is there any way to build a single one that can be used for both platforms?

Kara
  • 6,115
  • 16
  • 50
  • 57
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103

1 Answers1

103

Compile your library twice. Once using the device SDK, and again using the Simulator SDK.

Then use the lipo command line tool to create a "fat" library.

lipo -create libdevice.a libsimulator.a -output libcombined.a

That should give you what you need.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • Thanks for your quick and accurate answer. – Chilly Zhong Jun 08 '10 at 10:11
  • 1
    Is there anything special that needs to be done in the app using the library? I tried doing this with a library I'm making and got errors about architectures not matching when compiling a sample app that uses the library. – pr1001 Aug 22 '10 at 00:07
  • There isn't anything you need to do to differentiate between the architectures in the 'fat' library. You might see that error if the original libraries weren't built with the correct SDKs before using lipo. – Jasarien Aug 22 '10 at 01:24
  • How do you get the simulator SDK ? – CodenameLambda1 Jan 09 '14 at 10:37
  • @CodenameLambda1 just build for Simulator in Xcode - the resulting binary is compiled using the Simulator SDK. – Jasarien Jan 09 '14 at 14:22