I'm trying to use an external framework with my Swift application for Mac OS X. The external framework also uses Swift, and so depends on the Swift shared libraries (for example, libswiftCore.dylib
). This is verified by the command
$ otool -L PromiseKit.framework/PromiseKit
PromiseKit.framework/PromiseKit:
...
@rpath/libswiftCore.dylib (compatibility version 0.0.0, current version 0.0.0)
Looking up @rpath
I see
$ otool -l PromiseKit.framework/PromiseKit
...
cmd LC_RPATH
cmdsize 40
path @executable_path/Frameworks (offset 12)
So at runtime I expect @rpath
to resolve to @executable_path/Frameworks
The problem
I get a runtime error
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: .../PromiseKit.framework/Versions/A/PromiseKit
Reason: image not found
Looking in the folder containing my built executable, I don't see a Frameworks
folder.
Failed attempts to fix it
I tried setting EMBEDDED_CONTENT_CONTAINS_SWIFT
to YES
for my app, but this still doesn't create the Frameworks
folder.
I tried manually creating the Frameworks
folder and copying in the Swift shared libraries (from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
. This fixes the original error, but now I see duplicate symbol warmings like this one:
objc[64445]: Class _TtC10Foundation15NSSimpleCString is implemented in both
.../Frameworks/libswiftFoundation.dylib and
.../myApp.
One of the two will be used. Which one is undefined.
Question
Is it possible that the Swift libraries are being statically linked into my application? If so how do I turn that off and have XCode create the Frameworks
folder version instead?
I think the important point is that it's a command-line app. I tried creating a regular app and adding the framework and I get the expected
Frameworks
folder within my.app
package and it contains the Swift shared libraries