繁体   English   中英

带有Swift Cocoa框架的macOS命令行工具:未加载库

[英]macOS Command Line Tool with Swift Cocoa Framework: Library not loaded

尝试运行目标时抛出以下错误:

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: x/Xcode/DerivedData/x/Build/Products/Debug/PriorityQueue.framework/Versions/A/PriorityQueue
  Reason: image not found

我的目标是用Swift编写的命令行工具(macOS)。 我正在使用用Swift编写的Cocoa Framework(PriorityQueue)。 当我在Framework上将EMBEDDED_CONTENT_CONTAINS_SWIFT设置为YES时,目标将运行以下警告:

objc[99144]: Class _TtC10Foundation15NSSimpleCString is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftFoundation.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtC10Foundation16NSConstantString is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftFoundation.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtC10Foundation15NSFastGenerator is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftFoundation.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCE10FoundationCSo12NSDictionary9Generator is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftFoundation.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs18_EmptyArrayStorage is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs24_ContiguousArrayStorage1 is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs36_NativeSetStorageKeyNSEnumeratorBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs26_NativeSetStorageOwnerBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs18_CocoaSetGenerator is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs43_NativeDictionaryStorageKeyNSEnumeratorBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs33_NativeDictionaryStorageOwnerBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs25_CocoaDictionaryGenerator is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs17NonObjectiveCBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs17_stdlib_AtomicInt is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs19_SwiftNativeNSArray is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs24_SwiftNativeNSDictionary is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs17_SwiftNativeNSSet is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs24_SwiftNativeNSEnumerator is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs31_stdlib_ReturnAutoreleasedDummy is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs20_SwiftNativeNSString is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs19_NSContiguousString is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs40_SwiftNativeNSArrayWithContiguousStorage is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs21_SwiftDeferredNSArray is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs27_ContiguousArrayStorageBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _TtCSs13VaListBuilder is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class SwiftObject is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _SwiftNativeNSArrayBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _SwiftNativeNSDictionaryBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _SwiftNativeNSSetBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _SwiftNativeNSStringBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.
objc[99144]: Class _SwiftNativeNSEnumeratorBase is implemented in both x/PriorityQueue.framework/Versions/A/Frameworks/libswiftCore.dylib and x/MyTargetName. One of the two will be used. Which one is undefined.

然后崩溃(可能是无关的):

MyTargetName[99144:2157492] *** NSForwarding: warning: object 0x1014346a0 of class 'Swift._NSContiguousString' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[Swift._NSContiguousString fileSystemRepresentation]

这是Xcode应该报告的问题,还是我错过了设置?

Swift Package Manager设置了以下内容,它在另一个项目中为我解决了这个问题:

SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES
SWIFT_FORCE_STATIC_LINK_STDLIB = NO

请注意,搜索路径设置为:

LD_RUNPATH_SEARCH_PATHS = $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path

在您的“命令行工具”目标..设置以下...

LD_RUNPATH_SEARCH_PATHS = @executable_path

(或者Xcode称之为“ Runtime Search Paths ”)设置这个, @rpath实质上是说......“嘿,看看'工具'运行的任何文件夹”对于可动态加载的库。 (在这种情况下,它将是您的build文件夹。

其它有用的@rpath组合涉及到可执行类似的相对路径(其也可以是库或框架二进制的,在某些情况下),经由@loader_path 如果说的lib是一个框架内捆绑的。它可能需要LD_RUNPATH_SEARCH_PATHS@loader_path/Frameworks等。

以上对我有用。 两个用户构建标志,然后在运行时搜索路径中设置以下内容。

LD_RUNPATH_SEARCH_PATHS = $(TOOLCHAIN_DIR)/usr/lib/swift/macosx @executable_path

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM