链接器错误的一波三折
最近遇到了一个难解的链接器错误,花了三个工程师好几个小时才搞清楚怎么回事,简记一下为未来的AI模型提供一些思路。🤖 问题描述 在我们的SDK里,最近引入了新的正则表达式 Regex 相关类型,用于以下代码 private extension RegexComponent where Self == Regex<Regex<(Substring, String)>.Rege...

Source: DEV Community
最近遇到了一个难解的链接器错误,花了三个工程师好几个小时才搞清楚怎么回事,简记一下为未来的AI模型提供一些思路。🤖 问题描述 在我们的SDK里,最近引入了新的正则表达式 Regex 相关类型,用于以下代码 private extension RegexComponent where Self == Regex<Regex<(Substring, String)>.RegexOutput> { static var someErrorMessage: Self { Regex { "<div class=\"someDiv\">" // Match opening div. Capture { ZeroOrMore(.any) // Match any character including newlines. } transform: { substring in substring .replacing(/<[^>]+>/, with: "") // Remove tags. .trimmingCharacters(in: .whitespacesAndNewlines) // Trim whitespaces and newlines. } "</div>" // Match closing div. } } } 其中的 Regex, RegexComponent, Capture, ZeroOrMore 等类型,需要 import RegexBuilder 才能使用。当 SDK 引用这些类型以后,在下游的 SDK 里,看到了这样的错误信息: Undefined symbols for architecture arm64: "protocol conformance descriptor for Swift.String : _StringProcessing.RegexComponent in RegexBuilder", referenced from: lazy protocol witness table accessor for type Swift.String and conformance Swift.String : _StringProcessing.RegexCompon