2016-11-16 16 views
2

我正在嘗試使用對模塊的交叉引用來解決分段錯誤。不知道如何做這項工作。部分錯誤如下:分段錯誤:11 - 對模塊的交叉引用

1. While reading from /Users/damiandudycz/Library/Developer/Xcode/DerivedData/Hypno-azmcjycezcoqnfauqcbgimvipjyj/Build/Intermediates/Hypno.build/Debug-iphonesimulator/Hypno.build/Objects-normal/x86_64/WorldObjectBasedAugmentedRealityObject~partial.swiftmodule 
2. While deserializing 'WorldObjectBasedAugmentedRealityObject' (ClassDecl #12) 
3. While deserializing decl #31 (XREF) 
4. Cross-reference to module 'AugmentedReality' 
... AugmentedRealityView 
... in an extension in module 'AugmentedReality' 
... Object 
5. While loading members for 'AugmentedRealityView' at <invalid loc> 
6. While deserializing 'init' (ConstructorDecl #5) 
7. While deserializing decl #33 (XREF) 
8. Cross-reference to module 'UIKit' 
... UIView 
... init 
... with type (UIView.Type) -> (CGRect) -> UIView 

當我從其他模塊的某個子類繼承子類時,會發生問題。而其他模塊中的這個類繼承自UIView。 我準備了一個「空白」項目版本 - 我刪除了大部分文件和定義,只留下空的類和模塊。有人可以幫助我嗎?問題在類GoogleARObject中顯示 - 當此類被刪除或註釋它編譯時。

項目與空類: https://dl.dropboxusercontent.com/u/40968624/Hypno.zip

回答

12

更新:

與該問題從深層次看事實證明,我的答案是錯後。

你的代碼應該編譯得很好,因爲你沒有繼承AugmentedRealityView而只是嵌套類。

實際問題看起來像是一個編譯器bug。

您可以通過改變Swift Compiler解決這個問題 - Optimization LevelFast, Whole Module Optimization而不是None


原來的答案:

你正試圖從一個類繼承(AugmentedRealityView)從模塊的外部定義類,但它被標記publicfinal

public final class AugmentedRealityView: UIView { 
} 

open class WorldObjectBasedAugmentedRealityObject: AugmentedRealityView { 
} 

final禁止從這個類中繼承一般。

public允許從類中定義的子類(在Swift3中)。

若要使類的子類,能夠從它被定義的模塊外,使用open(新中Swift3):

open class AugmentedRealityView: UIView { 
} 

open class WorldObjectBasedAugmentedRealityObject: AugmentedRealityView { 
} 

要了解更多信息,請閱讀this

You can mark an entire class as final by writing the final modifier before the class keyword in its class definition (final class). Any attempt to subclass a final class is reported as a compile-time error.

.. 。

Open access applies only to classes and class members, and it differs from public access as follows:

Classes with public access, or any more restrictive access level, can be subclassed only within the module where they’re defined.

Class members with public access, or any more restrictive access level, can be overridden by subclasses only within the module where they’re defined.

Open classes can be subclassed within the module where they’re defined, and within any module that imports the module where they’re defined.

Open class members can be overridden by subclasses within the module where they’re defined, and within any module that imports the module where they’re defined.

+0

我不知道打開。感謝那。 (投票) –

+0

而且工作,謝謝你:)。這是否總是一個糟糕的設計來在擴展中包含嵌套類?如果它們只在模塊內部可見,那麼這可以嗎? –

+0

其實我在模塊的擴展模塊裏有更多這樣的開放類的地方,我在不同的模塊中繼承它們。但只有這一個會導致這個問題。這是爲什麼?例如我有公共最終類WebService:OperationQueue和它的擴展擴展WebService {open class RequestOperation:Operation {}} 同樣的情況,但工作正常,我可以繼承它在不同的模塊。 –

0

我知道這個問題很老,但我剛剛遇到了同樣的錯誤R:

Segmentation fault: 11 - Cross-reference to module 

在我的情況的解決辦法是禁用Use Legacy Swift Language Version(當然如果有可能爲您的項目)。

0

當您在同一時間引用同一個Framework的2個不同版本時會發生此錯誤。當您的代碼使用與庫使用的不同Swift版本時,可能會出現這種情況。

嘗試使用與Google AR使用的版本相同的Swift版本。

enter image description here

+0

老問題,但只是說,它不是Google AR,它是我自己開發的AR引擎。工作非常酷,但蘋果ARKit猛推:) –