库的Xcode Framework包装器(公开库头)

时间:2017-02-06 17:06:27

标签: ios objective-c xcode static-libraries

MyProject
    MyFramework
            MyLibrary.h
            libMyLibrary.a

我正在围绕一个静态库创建一个Framework包装器。标题(MyLibrary.h)需要可以从MyProject中的ViewController.m文件访问

#import "ViewController.h"
@import MyFramework;

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [[[MyLibrary alloc]init]test];
}

enter image description here 我已将MyLibrary.h设置为public

MyFramework.h包含行#import <MyFramework/MyLibrary.h>

'嵌入式二进制文件'设置为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

1 个答案:

答案 0 :(得分:0)

我设法通过将-ObjC添加到其他链接器标志来解决这个问题