Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping static library in Cocoa Touch Framework

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.

like image 378
tailec Avatar asked Apr 11 '17 08:04

tailec


People also ask

What is Cocoa Touch static library?

Cocoa Touch Static Library. A. A static library is a collection of compiled source files which is then linked directly into an app's binary.

Is XCFramework static or dynamic?

An XCFramework can be either static or dynamic and can include headers.

What is difference between framework and XCFramework?

Whereas Universal Frameworks contain many slices without knowledge of the platform SDK for each one, XCFrameworks contain many slices organized by platform. Because of this platform-awareness, an XCFramework can target more than one platform for the same architecture, which solves our problem.

What is static and dynamic library in Swift?

Static framework contain a static library packaged with its resources. Dynamic framework aka Embedded framework - from iOS v8 - contains the dynamic library and resources. In addition to that, dynamic framework can include different versions of the same dynamic library in a single bundle ( versioned bundle ).


1 Answers

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.

like image 180
Alessandro Ornano Avatar answered Oct 18 '22 04:10

Alessandro Ornano