14
votes

I have a fat static library with 2 architecture slices (armv7, arm64). I'm trying to make it work with swift and wrap it into Cocoa Touch Framework.

What I do:

  1. Create Cocoa Touch Framework project
  2. Drag .a static library with headers
  3. Set OTHER_LDFLAGS to -all_load
  4. Set ONLY_ACTIVE_ARCH to NO
  5. Set VALID_ARCHS and ARCHS to armv7 and arm64
  6. Build with Release build configuration
  7. Grab .framework file from DerivedData/../../Products/

When I put this .framework into my swift project, add to Embedded Binaries section in my targets general settings, import framework and use one of its classes, I'm getting undefined symbols for architecture arm64 or undefined symbols for architecture armv7.

EDIT:
Not sure if it helps but I've noticed that size of static library is about 34MB but size of generated .framework is about 12MB.

EDIT 2:
I ran nm -arch arm64 -g myLibraryName on both static library and generated dynamic library. The dynamic library doesn't contain all symbols that static library has. Seems like XCode build process strips lots of them.

1
To clarify do you want to distribute the library inside your framework? Do you just want to be able to use library inside your framework or are you also trying to expose the library to apps that embed your framework? Finally is there a .dylib version available of the static library? - tdbit
@tdbit I'm trying to wrap static library to Cocoa Touch Framework because I want to use swift. As you know, swift doesn't support static libraries. No, .dylib is not available. - tailec
Make sure you are creating library proper way. check below links for proper way to create dynamic framework. > insert.io/frameworkios8xcode6 > possiblemobile.com/2016/08/ios-frameworks-part-2-build-and-ship - pdubal
Im afraid there is not enough info to find the source of problem yet. Have you added your lib to linked libraries? What target architectures selected in build settings? Have you build for simulator target or for a device? What symbols are undefined as there is a chance what some dylib is used in yor library? - FalconSer
Hi, did you find a way to do this? I'm facing the same issue… - AnthoPak

1 Answers

3
votes

I think you have also forgotten to add :

Project->Target->Build Phases->Link Binary With Libraries: add + the: libz.dylib or libz.tbd (Since Xcode 7 the *.dylib files are now *.tbd files)

Be sure to also clean the folder: /User/yourname/Library/Developer/XCode/DerivedData

P.S: If you want you should also be able to add the libz.tbd from "Other Linker Flags" in the Build Settings by adding the argument -lz.