我正在尝试在我的 Mac OS X Swift 应用程序中使用外部框架。外部框架也使用 Swift,因此依赖于 Swift 共享库(例如,libswiftCore.dylib
)。这是通过命令验证的
$ otool -L PromiseKit.framework/PromiseKit
PromiseKit.framework/PromiseKit:
...
@rpath/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)
抬头@rpath
我看到
$ otool -l PromiseKit.framework/PromiseKit
...
cmd LC_RPATH
cmdsize 40
path @executable_path/Frameworks (offset 12)
所以在运行时我希望@rpath
解决@executable_path/Frameworks
问题
我收到运行时错误
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: .../PromiseKit.framework/Versions/A/PromiseKit
Reason: image not found
查看包含我构建的可执行文件的文件夹,我没有看到Frameworks
文件夹。
尝试修复失败
我尝试为我的应用程序设置EMBEDDED_CONTENT_CONTAINS_SWIFT
,YES
但这仍然没有创建Frameworks
文件夹。
我尝试手动创建Frameworks
文件夹并在 Swift 共享库中复制(从/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
. 这修复了原始错误,但现在我看到像这样的重复符号变暖:
objc[64445]: Class _TtC10Foundation15NSSimpleCString is implemented in both
.../Frameworks/libswiftFoundation.dylib and
.../myApp.
One of the two will be used. Which one is undefined.
问题
Swift 库是否有可能被静态链接到我的应用程序中?如果是这样,我该如何关闭它并让 XCode 创建Frameworks
文件夹版本?
我认为重要的一点是它是一个命令行应用程序。我尝试创建一个常规应用程序并添加框架,我
Frameworks
在我的包中获得了预期的文件夹.app
,它包含 Swift 共享库