Swift:从 iOS 7 编译存档时出现分段错误
Posted
技术标签:
【中文标题】Swift:从 iOS 7 编译存档时出现分段错误【英文标题】:Swift: segmentation fault when compiling for Archive from iOS 7 【发布时间】:2014-11-04 09:05:11 【问题描述】:我一直有这个问题,所以我开始用 Swift 为 iPhone 和 iPad 创建一个新的单视图应用程序。 当目标是 ios 8.1 时,一切正常,但如果我设置 iOS 7.1(或 7),我会遇到分段错误。当我转到产品>存档时,当我在模拟器或我的设备中运行项目时,就会发生这种情况,一切都很好。我尝试了 iOS 7 和 8 模拟器,它可以编译。 正如我所说,问题不在于代码,因为即使是新创建的项目,它的行为也是如此。
CompileSwift normal armv7 /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift
cd /Users/francesco/Documents/XCode Projects/Prova
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file "/Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift" "/Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift" -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift /Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o
1. While type-checking 'ViewController' at /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift:11:1
Command failed due to signal: Segmentation fault: 11
有人知道这个问题吗?
更新:我可以将 armv7s 和 arm64 定位到 iOS 7,armv7 是导致问题的原因;如果 armv7 针对 iOS 8 而其他针对 iOS 7,则一切正常。在我看来,这不是一个好的解决方案,因为在旧设备上支持旧操作系统更为重要。
【问题讨论】:
【参考方案1】:我遇到了同样的问题,直到有人告诉我这是证书的问题。转到开发中心并重新生成您的证书和配置文件。之后它应该可以工作了!
【讨论】:
全部设置为自动,所以 Xcode 会发现并(尝试)修复问题,对吧? 不,这无济于事。您还必须更新您的证书(上传新的代码签名请求 (.csr) 文件并重新创建所有配置文件)。 天哪。这对我来说绝对是。我去了首选项>帐户>详细信息,然后单击证书上的刷新按钮。不再有段 11 故障。堆栈跟踪是疯狂的误导——谈论类型检查的错误。我正在移动可能模棱两可的 TypeAlias,各种各样的东西。谢谢@Hannes!【参考方案2】:关闭 Xcode 并打开另一个项目,然后加载回这个项目,解决了这个问题。 我猜这是一个错误。
【讨论】:
【参考方案3】:我在 Xcode 6.1 上遇到了同样的问题。构建和运行 Swift 项目没有问题,归档导致错误:
Command failed due to signal: Segmentation fault: 11
1. While type-checking <my Swift class>
将项目的部署目标从7.0
更改为7.1
解决了问题,现在可以归档应用了。
【讨论】:
【参考方案4】:我遇到了同样的问题,尝试选择的答案(即关闭和重新打开 Xcode 等)以及其他实验都没有帮助。根据堆栈跟踪,以下代码失败:
var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell
在随后的代码中,我将 cell 和 cell2 都视为可选项,因此我没有费心解开这些赋值。显然,斯威夫特讨厌它,以至于对我造成了段错误。经过一些实验,我将代码更改为
var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell!
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell!
并且 Swift 分段错误停止了。问题出在 Xcode 6.1.1 (6A2008A) 上。
如果您仍然遇到此问题,您应该查看堆栈跟踪提到崩溃发生的位置。它会说一些关于发出代码的信息,并且应该是可定位的。
【讨论】:
【参考方案5】:我遇到了同样的问题——编译在模拟器和设备上都可以正常运行,但在归档期间我会得到seg fault 11
。我在这里尝试了其他一些解决方案,但仍然出现错误。
我将原因隔离为使用泛型和 NSCoding 协议的方法。删除协议解决了这个问题。
这导致了段错误:
func saveToDefaults<T: NSCoding>(objectToSave : T?, key : String)
但将其更改为修复它:
func saveToDefaults<T>(objectToSave : T?, key : String)
if let objectToSave = objectToSave as? NSCoding
...
它不像原来的那么健壮,但它可以编译。
【讨论】:
以上是关于Swift:从 iOS 7 编译存档时出现分段错误的主要内容,如果未能解决你的问题,请参考以下文章
在 iOS 项目(在 Swift 中)设置 Google Analytics 时出现“保护体可能无法通过”错误 [重复]
为啥在编译我的代码C(linux)时出现分段错误(核心转储)[关闭]
扩展 UIViewControllerAnimatedTransitioning 时出现分段错误