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

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

问题描述

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



这是可选的扩展之一:

 扩展可选{
///如果该值当前为零,则展开返回'defaultValue'的值
func或(defaultValue :T)→> T {
switch(self){
case .None:
return defaultValue
case .Some(let value):
return value
}






这个方法在游乐场或应用程序中效果很好,代码是在应用程序的主要部分编译的。但是,当我尝试将它编译为框架时,应用程序(甚至框架的测试)产生以下链接器错误:


未定义的符号体系结构i386:__TFSq2orU__fGSqQ__FQQ,
引用自:
__TFC18SwiftPlusPlusTests27Optional_SwiftPlusPlusTests13testOrWithNilfS0_FT_T_
可选+ SwiftPlusPlusTests.o


类似下面的方法,链接罚款(注意,它不是通用的)

$ $ p $扩展字符串{
///通过重复'times'times来返回一个字符串
func repeat(times:Int) - >字符串{
var result =
for i in 0..times {
result + = self
}
返回结果
}
}

在github上我的仓库中还有另外两个扩展:SwiftPlusPlus 也不链接(都在通用结构上)。你会重现错误,如果你拉最新的提交,构建框架,然后尝试运行单元测试。

到目前为止,我试图运行字符串在输出的框架和中间文件上,我没有看到这些扩展的符号,但我确实看到字符串中的重复方法扩展的符号。所以它甚至不会将它们编译到库中。



有人知道为什么符号没有在框架中定义吗?

编辑


  • 这里是指向我的可选扩展程序的链接

  • 这里是链接到测试文件,当试图编译测试目标时导致链接器错误


解决方案

发布在苹果开发者论坛上,一名苹果员工回应说这是一个已知的错误。


它看起来像编译器获得了当它们居住时泛型扩展中的方法的错误符号名称错误一个不同的框架。


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.

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:

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
    }
}

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.

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?

Edit

  • 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

解决方案

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天全站免登陆