jbr*_*nan 16 macos frameworks static-libraries swift
我正在Proto.framework为Swift中的OS X 编写动态Framework().我想要包含一个libstat.a用Objective C编写的静态库()中的代码.这就是我所拥有的:
// Dynamic.swift in Proto.framework
class Dynamic {
func doSomethingWithStat() {
Stat().statThing()
}
}
// Stat.h in libstat.a static library
@interface Stat : NSObject
- (void)statThing;
@end
// Stat.m
@implementation Stat
- (void)statThing {
NSLog(@"OK");
}
@end
Run Code Online (Sandbox Code Playgroud)
在我的Proto.framework目标中,我将它链接到libstat.a.当我尝试构建Proto时,自然它无法编译,因为它找不到定义Stat().statThing().它不知道我的静态库的符号.我该怎么说呢?
对于应用程序,我会使用桥接头#import <Stat/Stat.h>.但编译器错误并告诉我Bridging headers aren’t allowed in frameworks.好.
所以我把它包含在我的"伞头"(Proto.h)中,但这告诉我error: include of non-modular header inside framework module.好.
即使在干净的构建之后,使我的Stat库目标Defines module: YES似乎也不会改变错误.所以我不知道该怎么做.
有人能指出我正确的方向吗?
小智 9
最简单的方法是使用模块映射文件.下面我假设你有Proto.framework一个单独的项目,它被称为Proto.
module.modulemap在框架中创建一个包含以下内容的文件(根据需要替换头文件的路径):_
framework module Proto {
umbrella header "Proto.h"
// Load a C header to be used in Swift - here /usr/include/sys/stat.h:
header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stat.h"
export *
module * { export * }
}
Run Code Online (Sandbox Code Playgroud)
Module Map File部分Packaging.输入$(SRCROOT)/Proto/module.modulemap而已.从现在开始,您应该能够使用stat.hSwift中声明的任何内容.
| 归档时间: |
|
| 查看次数: |
7645 次 |
| 最近记录: |