Swift 框架不包括从扩展到通用结构的符号 [英] Swift Framework does not include symbols from extensions to generic structs

查看:19
本文介绍了Swift 框架不包括从扩展到通用结构的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将我的框架与利用该框架的代码链接起来.具体来说,链接器无法找到泛型结构的扩展符号.

I am having trouble linking my framework with code that takes advantage of that framework. Specifically, the linker isn't able to find the symbols for extensions for generics structs.

这是 Optional 的其中一个扩展的样子:

This is what one of the extensions looks like for Optional:

extension Optional {
    /// Unwrap the value returning 'defaultValue' if the value is currently nil
    func or(defaultValue: T) -> T {
        switch(self) {
            case .None:
                return defaultValue
            case .Some(let value):
                return value
        }
    }
}

如果代码在应用程序的主要部分中编译,则此方法在游乐场或应用程序中非常有效.但是,当我尝试将其编译到框架中时,应用程序(甚至框架的测试)会产生以下链接器错误:

This method works great in a playground or in an app if the code is compiled within the main part of the app. However, when I try to compile this into a Framework, apps (and even the tests for the framework) produce the following linker error:

架构 i386 的未定义符号:__TFSq2orU__fGSqQ__FQQ",参考自:__TFC18SwiftPlusPlusTests27Optional_SwiftPlusPlusTests13testOrWithNilfS0_FT_T_在 Optional+SwiftPlusPlusTests.o

Undefined symbols for architecture i386: "__TFSq2orU__fGSqQ__FQQ", referenced from: __TFC18SwiftPlusPlusTests27Optional_SwiftPlusPlusTests13testOrWithNilfS0_FT_T_ in Optional+SwiftPlusPlusTests.o

类似以下的方法,链接很好(注意,它不是泛型的)

Similar methods like the one following, link fine (notice, it is not on a generic)

extension String {
    /// Returns a string by repeating it 'times' times
    func repeat(times: Int) -> String {
        var result = ""
        for i in 0..times {
            result += self
        }
        return result
    }
}

我在 github 上的存储库中还有另外两个扩展:SwiftPlusPlus,它们也没有链接(都在通用结构上).如果您拉取最新的提交,构建框架,然后尝试运行单元测试,您将重现错误.

There are two other extensions within my repository on github: SwiftPlusPlus that also do not link (both on generic strucs). You will reproduce the errors if you pull the latest commit, build the framework, and then try to run the unit tests.

到目前为止,我已经尝试在输出的框架和中间文件上运行字符串",我没有看到这些扩展的符号,但我确实看到了 repeat 方法扩展的符号代码>字符串.所以它甚至似乎都没有将它们编译到库中.

So far I have tried to run "strings" on the outputted framework and intermediate files and I do not see the symbols for these extensions but I do see the symbols for the repeat method extension on String. So it doesn't even seem to be compiling them into the library.

有谁知道为什么框架中没有定义符号?

Does anyone know why the symbols are not defined in the framework?

编辑

  • 这里是我的可选扩展的链接
  • 这里是导致链接器错误的测试文件的链接尝试编译测试目标时
  • Here is a link to my Optional Extension
  • Here is a link to the test file that causes the linker error when trying to compile the test target

推荐答案

发布在 Apple Developer论坛和苹果员工回应说这是一个已知的错误.

I posted on the Apple Developer forums and an Apple employee responded that this is a known bug.

当通用扩展中的方法位于不同的框架中时,编译器似乎错误地获取了错误的符号名称.

It looks like the compiler gets the mangled symbol names of methods in generic extensions wrong when they live in a different framework.

这篇关于Swift 框架不包括从扩展到通用结构的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆