问题描述
我有一个带有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.
我的所作所为:
- 创建Cocoa Touch Framework项目
- 拖动带有标题的静态库
- 设置
OTHER_LDFLAGS
到-all_load
- 设置
ONLY_ACTIVE_ARCH
至否
- 设置
VALID_ARCHS
和ARCHS
至armv7
和arm64
- 使用发布版本配置构建
- 从DerivedData获取.framework文件/../../产品/
- Create Cocoa Touch Framework project
- Drag .a static library with headers
- Set
OTHER_LDFLAGS
to-all_load
- Set
ONLY_ACTIVE_ARCH
toNO
- Set
VALID_ARCHS
andARCHS
toarmv7
andarm64
- Build with Release build configuration
- 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中包装静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!