【问题标题】:Xcode Framework wrapper for Library ( Exposing library headers)库的 Xcode 框架包装器(公开库头)
【发布时间】: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];
}

我已将 MyLibrary.h 设置为 public

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-18
    • 2015-12-03
    • 1970-01-01
    相关资源
    最近更新 更多