【发布时间】:2017-02-06 17:06:27
【问题描述】:
MyProject
MyFramework
MyLibrary.h
libMyLibrary.a
我正在围绕一个静态库创建一个框架包装器。标题(MyLibrary.h)需要可以从 MyProject 中的 ViewController.m 文件访问
#import "ViewController.h"
@import MyFramework;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[[MyLibrary alloc]init]test];
}
MyFramework.h 包含行 #import <MyFramework/MyLibrary.h>
'Embedded Binaries' 设置为 MyFramework
当我运行上面的代码时,我得到...
架构 x86_64 的未定义符号: “_OBJC_CLASS_$_MyLibrary”,引用自: ViewController.o 中的 objc-class-ref ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
我发现解决这个问题的唯一方法是在 MyFramework 中创建一个私有类(称为 TestClass)并分配 MyLibrary。我假设这会强制 MyLibrary 在运行时链接并可以从 ViewController 访问。 但这太丑了,我错过了什么?
#import "TestClass.h"
#import "MyLibrary.h"
@implementation TestClass
- (id)init {
if (self = [super init]) {
[MyLibrary alloc]; //solves the problem of MyLibrary being accessable from ViewController
}
return self;
}
@end
【问题讨论】:
-
您需要在
ViewController.m类中添加#import "MyFramework.h"而不是@import。 -
谢谢,刚刚试过了,还是一样的错误。
标签: ios objective-c xcode static-libraries