簡體   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