使用Swift,XCode6-Beta进行静态链接 [英] Static Linking with Swift, XCode6-Beta

查看:82
本文介绍了使用Swift,XCode6-Beta进行静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将Obj-C库移植到Swift,但是遇到一个问题,当Swift代码在项目中时,链接器无法构建静态库.

I've been experimenting with porting an Obj-C library to Swift, and I've run into a problem where the linker fails to build a static library when Swift code is in the project.

作为最低限度的复制者,进入XCode6并创建一个新的iOS静态库.它会为您提供一个带有空白.h和.m文件的项目.这样可以编译的很好.然后,将新的.swift文件添加到项目中(创建或不创建标题桥). 应该也可以正常编译,但是在链接期间失败:

As a minimal reproducer, go into XCode6 and create a new iOS Static Library. It'll give you a project with a blank .h and .m file. This will compile fine. Then, add a new .swift file to the project (with or without creating a header bridge). This too should compile fine, but instead it fails during linking:

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 arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]

如果我瞄准模拟器或设备,则会发生这种情况.看起来,即使目标是静态库,项目中拥有Swift文件也可能导致它使用通常为可执行程序保留的链接器选项?我对构建选项了解不足,无法确定这是Beta中的错误还是我应该配置的某些选项.在这样一个琐碎的例子上,该构建合法地失败似乎是值得怀疑的.有什么想法吗?

This happens if I'm targeting the simulator or the device. It looks like perhaps having the Swift file in the project is causing it to use linker options normally reserved for executables, even though the target is a static library? I don't know enough about the build options to know if this is a bug in the beta, or some option I should be configuring. It seems questionable that the build would legitimately fail on such a trivial example. Any thoughts?

推荐答案

要在评论中进行一些讨论后回答我自己的问题,目前尚无法构建包含Swift代码的静态库.我正在从Beta 4开始编写此代码,发行说明仍在"Xcode 6 beta 4中的已知问题"下显示:

To answer my own question after some discussion in the comments, it is simply not possible to build static libraries that include Swift code yet. I'm writing this as of Beta 4, and the release notes still say, under "Known issues in Xcode 6 beta 4":

Xcode不支持构建包含Swift代码的静态库. (17181019)

这篇关于使用Swift,XCode6-Beta进行静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆