Segmentation fault: 11 - Cross-reference to module

微笑、不失礼 提交于 2019-12-23 10:19:56

问题


I'm trying to resolve an Segmentation Fault with Cross-references to modules. Don't know how to make this work. Part of error below:

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

Problem occurs when I'm subclassing a class that is a subclass of something from other module. And this class in other module inherits from UIView. I have prepared an "empty" project version - I deleted most of the files and definitions, only empty classes are left and modules. Could someone help me with this? Problem shows in class GoogleARObject - when this class is deleted or commented it compiles.

Project with empty classes: https://dl.dropboxusercontent.com/u/40968624/Hypno.zip


回答1:


Update:

After having a deeper look in the issue it turns out that my answer is wrong.

Your code should compile fine, as you do not subclass AugmentedRealityView but a nested class.

The actual issue looks like a compiler bug to me.

You can fix the issue by changing the Swift Compiler - Optimization Level to Fast, Whole Module Optimization instead of None:


Original Answer:

You are trying to inherit from a class (AugmentedRealityView) from outside the module the class is defined in, but it is marked public and final:

public final class AugmentedRealityView: UIView {
}

open class WorldObjectBasedAugmentedRealityObject: AugmentedRealityView {
}

final forbids to inherit from this class in general.

public allows to subclass from within the module the class is defined in (in Swift3).

To make a class subclass-able from outside the module it is defined in, use open (new in Swift3):

open class AugmentedRealityView: UIView {
}

open class WorldObjectBasedAugmentedRealityObject: AugmentedRealityView {
}

To learn more, read 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.




回答2:


This error happens when you are referencing 2 different version of a same Framework at the same time. This can be the case when your code is using a different Swift version than one used by the library.

Try to use the same version of Swift than the one used by Google AR.




回答3:


I know this question is old, but I just encountered the same error:

Segmentation fault: 11 - Cross-reference to module

The solution in my case was to disable Use Legacy Swift Language Version (of course if it's possible for your project).



来源:https://stackoverflow.com/questions/40632924/segmentation-fault-11-cross-reference-to-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!