本文介绍了在Cocoa Touch Framework中包装静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有2个架构片的胖静态库(armv7,arm64)。
我正在尝试使用swift并将其包装到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.

我的所作所为:


  1. 创建Cocoa Touch Framework项目

  2. 拖动带有标题的静态库

  3. 设置 OTHER_LDFLAGS -all_load

  4. 设置 ONLY_ACTIVE_ARCH

  5. 设置 VALID_ARCHS ARCHS armv7 arm64

  6. 使用发布版本配置构建

  7. 从DerivedData获取.framework文件/../../产品/

  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/

当我把这个.framework放到我的swift项目中时,在我的目标常规设置中添加嵌入式二进制文件部分,导入框架并使用其中一个类,我得到架构的未定义符号arm64 架构armv7的未定义符号

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.

编辑:

不确定它是否有帮助但我已经注意到了虽然静态库的大小约为34MB,但生成的.framework的大小约为12MB。


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.

编辑2:

我在静态上运行 nm -arch arm64 -g myLibraryName 库和生成的动态库。动态库不包含静态库具有的所有符号。看起来像XCode构建过程剥离了很多。

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.

推荐答案

我想你也忘了添加:

项目 - > 目标 - > 构建阶段 - > 将二进制文件链接到库
add +: libz.dylib libz.tbd
(自Xcode以来) 7 * .dylib 文件现在* .tbd 文件)

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)

请务必同时清理文件夹: / User / yourname / Library / Developer / XCode / DerivedData

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

PS:如果你想要你也应该能够在 Build中从Other Linker Flags添加 libz.tbd 设置,添加参数-lz。

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.

这篇关于在Cocoa Touch Framework中包装静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:04