我一直在尝试将一个Obj-C库移植到Swift,我遇到了一个问题,当Swift代码在项目中时,链接器无法构建静态库.
作为最小的再现器,进入XCode6并创建一个新的iOS静态库.它会给你一个带有空白.h和.m文件的项目.这将编译好.然后,将新的.swift文件添加到项目中(创建或不创建标题桥).这也应该编译好,但在链接期间失败:
Libtool /Users/alexkarantza/Library/Developer/Xcode/DerivedData/Test-alenfoymgkewlghfjjvizjjuvign/Build/Products/Debug-iphonesimulator/libTest.a normal i386
cd /Users/alexkarantza/Workspace/Test
export IPHONEOS_DEPLOYMENT_TARGET=8.0
export PATH="/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only i386 -syslibroot /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -L/Users/alexkarantza/Library/Developer/Xcode/DerivedData/Test-alenfoymgkewlghfjjvizjjuvign/Build/Products/Debug-iphonesimulator -filelist /Users/alexkarantza/Library/Developer/Xcode/DerivedData/Test-alenfoymgkewlghfjjvizjjuvign/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/i386/Test.LinkFileList -ObjC -L/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -rpath -Xlinker /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -force_load -Xlinker /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a -Xlinker -sectalign -Xlinker __SWIFT -Xlinker __ast -Xlinker 4 -Xlinker -sectcreate -Xlinker __SWIFT -Xlinker __ast -Xlinker /Users/alexkarantza/Library/Developer/Xcode/DerivedData/Test-alenfoymgkewlghfjjvizjjuvign/Build/Intermediates/Test.build/Debug-iphonesimulator/Test.build/Objects-normal/i386/Test.swiftmodule -o /Users/alexkarantza/Library/Developer/Xcode/DerivedData/Test-alenfoymgkewlghfjjvizjjuvign/Build/Products/Debug-iphonesimulator/libTest.a
error: /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only …Run Code Online (Sandbox Code Playgroud) 标题说明了一切.我在SWIFT_MODULE_NAME的构建设置中搜索过,但没有任何内容.我也在线搜索,并且有对此名称的引用,但没有关于如何定义的信息.此外,我在Apple Docs中找不到任何提及SWIFT_MODULE_NAME的信息.
我知道这一点:它用于"Objective-C Generated Interface Header Name"构建设置,可以通过双击设置值来查看:
$(SWIFT_MODULE_NAME)-Swift.h
它用于弥合Objective-C和Swift之间的差距,并且只出现在包含Swift文件的项目中(以及我假设的Objective-C文件).截至发布时,Xcode 7.3是最新最好的.
但是,这个值定义在哪里,我该如何修改它?
构建现代框架说每个应用程序都有自己的自定义框架副本.现在,Xcode的支持iOS的框架,它仍然是真实的框架是静态库只是更方便?如果这是真的,那么为什么选择静态库模板呢?否则,一旦Swift支持静态库,我应该将所有必需的自定义框架转换为静态库吗?
为什么Swift不支持静态库?
我看到了这个解释,但我不明白这个推理.
当前运行时不附带操作系统,因此静态库将导致最终可执行文件中的多个运行时.对于与较新的OS或Swift的兼容性,静态链接的运行时将更难以修补....运行时间不断变化.我们需要动态链接它以便能够处理未来的前向部署问题. - 乔格罗夫
https://twitter.com/owensd/status/555060783407591424
请解释.