ios - Xcode 6 链接器错误 - 体系结构 armv7 的 undefined symbol

标签 ios xcode swift linker upgrade

升级到 Xcode 6 beta 7(现在仍然使用 Xcode 6 GM)后,我无法链接我的 Swift 应用程序。我收到如下错误:

Undefined symbols for architecture armv7: "_swift_stdlib_compareNSStringDeterministicUnicodeCollation", referenced from:

...

ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

我看到其他 SO 帖子建议删除 Derived Data 文件夹和/或使用 Clean Build Folder 选项来解决此错误,但该解决方案对我的情况毫无帮助。自 Xcode 6 beta 5 以来,我的代码或我使用的 CocoaPods 没有任何变化,这是它最后一次工作。

有什么想法吗?

编辑:

错误日志的完整发布:

Undefined symbols for architecture arm64: "_swift_stdlib_compareNSStringDeterministicUnicodeCollation", referenced from: TFC12MyProject21BarcodeViewController13captureOutputfS0_FTGSQCSo15AVCaptureOutput_24didOutputMetadataObjectsGSQGSaPSs9AnyObject___14fromConnectionGSQCSo19AVCaptureConnection__T_ in BarcodeViewController.o "__TFSs21_arrayConditionalCastU___FGSaQ__GSqGSaQ0_", referenced from: TFC12MyProject27SessionsTableViewController17viewWillDisappearfS0_FSbT_ in SessionsTableViewController.o "__TFSs15_arrayForceCastU___FGSaQ__GSaQ0", referenced from: __TFC12MyProject7RestApi12tokenMappingfS0_FT_CSo15RKEntityMapping in RestApi.o __TFC12MyProject28AttendeesTableViewControllerg24fetchedResultsControllerCSo26NSFetchedResultsController in AttendeesTableViewController.o __TFC12MyProject27SessionsTableViewControllerg24fetchedResultsControllerCSo26NSFetchedResultsController in SessionsTableViewController.o __TFC12MyProject21BarcodeViewController13startScanningfS0_FT_Sb in BarcodeViewController.o "__TFSs26_forceBridgeFromObjectiveCU__FTPSs9AnyObject_MQ__Q_", referenced from: __TFC12MyProject7RestApi12resetRestKitfS0_FT_T_ in RestApi.o __TFC12MyProject16BluetoothManager17_startAdvertisingfS0_FT_T_ in BluetoothManager.o __TFC12MyProject19LoginViewController32registerForKeyboardNotificationsfS0_FT_T_ in LoginViewController.o __TFC12MyProject19LoginViewController35deregisterFromKeyboardNotificationsfS0_FT_T_ in LoginViewController.o __TFC12MyProject19LoginViewController16callProcessLoginfS0_FT_T_ in LoginViewController.o __TFC12MyProject21CheckinViewController16enableBeaconModefS0_FT_T_ in CheckinViewController.o __TFC12MyProject21BarcodeViewController13startScanningfS0_FT_Sb in BarcodeViewController.o ... ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

这里发生的事情与您的派生数据位置无关。

构建 swift 应用程序时,它会经历几个步骤:

  • 编写辅助文件

  • 创建产品结构

  • 为各个架构编译swift源码

  • 复制资源规则plist

  • 复制应用桥接头

  • 链接到每个架构的 swift 运行时库

  • 为每个架构复制应用程序 swift 模块

  • 创建应用程序二进制文件

  • 复制资源构建阶段

  • 将 swift 标准库复制到应用程序中

  • 打包

  • 签名

哇!好多啊。链接到 swift 运行时库时,您的构建失败。它们位于 Xcode 开发人员目录内的 Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos 中。具体来说,未正确链接的库是 libswiftCore.dylib。如果您在该库上使用 nm,您可以看到它定义了您的第一个缺失符号:

quellish% nm /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib | grep compareNSStringDeterministicUnicodeCollation
00197c8c T _swift_stdlib_compareNSStringDeterministicUnicodeCollation
000000000018352c T _swift_stdlib_compareNSStringDeterministicUnicodeCollation

您还可以使用lipo 来查看文件中有哪些架构:

quellish% xcrun lipo -info /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib
Architectures in the fat file: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib are: armv7 arm64

它包含 armv7 和 arm64。问题不在于库架构。

链接到 swift 标准库无效。源代码控制或迁移 Xcode 版本可能导致您的项目文件放弃了部分链接步骤,或者它根本无法找到它需要链接的库。 Xcode 项目文件很复杂并且使用了很多引用 - 合并等可能导致关键引用与链接步骤分离。如果没有完整的构建日志并查看您的机器,可能无法分辨。

您可能猜到了,这个库与项目的派生数据位置无关。

不幸的是,最好的前进方式是重新创建项目文件。将损坏的项目的构建日志与正确构建的快速项目进行比较可能会提供一些见解,但这也可能是浪费时间 - 某些可修复的问题可能是问题,但更有可能不是。

我鼓励您提交一个错误并将麻烦的项目文件包含在其中。

关于ios - Xcode 6 链接器错误 - 体系结构 armv7 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25765352/

相关文章:

ios - 数据更改时,是否始终需要IGListkit中的performUpdatesAnimated?

iphone - 测试账号恢复MKStoreKit中未购买的商品

swift - 如何在 UIActionSheet 中添加多行文本

ios - 如何在 iOS 应用中获取亚马逊产品评论和排名信息?

ios - 签署 "Runner"需要开发团队。在签名和功能编辑器中选择一个开发团队

node.js - 如何以及何时使用谷歌云函数中的 promise 正确返回值?

ios - 表达式类型不明确,没有更多上下文(枚举)

python - JSON 到 iOS 字符串文件

ios - 如何使用 Google Sheets API V4 从 Swift 2.2 创建新的 Google Sheet?

ios - 根据星期几显示不同的消息