objective-c - 尝试将 Swift 与 Obj C header 用于 Coda2 插件。获取错误 : Undefined symbols for architecture x86_64

标签 objective-c cocoa swift coda

尝试使用 swift 为 Coda 2.5 构建插件。我收到此错误:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_CodaPlugInsController", referenced from:
      _get_field_types_PowPlugInViewController in PowPlugInViewController.o
      _get_field_types_PowPlugIn in PowPlugin.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经清理了我的构建文件夹。 我已经创建导入语句并将其添加到 project name-bridging-swift.h

下面是我的项目。

CodaPlugInsController.h

您可以在此处找到此文件。 https://github.com/panicinc/CodaPluginKit/tree/master/Cocoa%20Plug-ins 说明: 这个 header 提供了实现 Coda 的协议(protocol)和设施 基于文本的语法验证器和侧边栏插件。

CodaPow-Bridging-Header.h

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "CodaPlugInsController.h"

PowPlugin.swift

import Foundation

class PowPlugIn: NSObject, CodaPlugIn, CodaSidebarPlugIn {
    let PowBundle: CodaPlugInBundle
    let PowController: CodaPlugInsController

    required init(plugInController: CodaPlugInsController, plugInBundle: CodaPlugInBundle) {
        self.PowBundle = plugInBundle
        self.PowController = plugInController
        super.init()
    }

    func name() -> String {
        return "Coda Pow"
    }

    func didLoadSiteNamed(name: String!) {

    }

    func viewController() -> NSViewController {
       return PowPlugInViewController(nibName: "PowPlugInView", plugInBundle: PowBundle, plugInController: PowController)!
    }
}

PowPlugInViewController.swift

import Foundation

class PowPlugInViewController: NSViewController, CodaSidebarViewController {
    let PowController: CodaPlugInsController
    init?(nibName: String, plugInBundle: AnyObject, plugInController: CodaPlugInsController) {
        self.PowController = plugInController
        super.init(nibName: nibName, bundle: plugInBundle as? NSBundle)
    }
    //  Xcode Says I need this.
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

我还有两个源文件。 ServerAndHosts.swiftShell.swift 它们不使用 CodaPlugInsController.h 中的任何类。 Shell.swift 文件只是一组类函数。

编辑: 我可以使用 swift,只要我不从 CodaPlugInsController.h 继承或传入一个对象即可。

项目的 Swift 和 Obj-C 版本: https://www.dropbox.com/sh/bsw8cinn7kp9kfe/AAAgG_B44dbHNP5-JwJ3Amf8a?dl=0

最佳答案

项目编译,所以桥接 header 可能不是问题。

您在链接阶段失败,编译器无法为您当前的架构找到一组符号。 这可能意味着

1) Coda 库不是为你的架构编译的

2) 链接器根本找不到库。

我查看了您的 Obj-C 项目,Coda 库似乎不在该项目中,所以我猜它是 #2。您要么想以某种方式将 lib 移动到项目中,要么在项目的“库搜索路径”中添加指向系统其他位置的 lib 的路径

关于objective-c - 尝试将 Swift 与 Obj C header 用于 Coda2 插件。获取错误 : Undefined symbols for architecture x86_64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27327693/

相关文章:

objective-c - 按下时更改 UIView 的外观(但尚未释放)

objective-c - NSMutableDictionary 实例变量不在循环外保留键值

macos - 核心数据子/父保存异常

cocoa - NSComboBox 对象类型

swift - 按字母顺序键将数组插入 swift 字典

ios - 隐藏导航 Controller 搜索栏并以编程方式打开大标题

objective-c - 更新 sqlite3 API

ios - 照片框架 : Connection to assetsd was interrupted or assetsd died

objective-c - 我的 OS X 应用不想打开它创建的文件

swift - 生成多页 PDF UIView