简体   繁体   English

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

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

The following error is thrown when trying to run my target: 尝试运行目标时抛出以下错误:

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

My target is a Command Line Tool (macOS) written in Swift. 我的目标是用Swift编写的命令行工具(macOS)。 I'm using a Cocoa Framework (PriorityQueue) written in Swift. 我正在使用用Swift编写的Cocoa Framework(PriorityQueue)。 When I set EMBEDDED_CONTENT_CONTAINS_SWIFT to YES on the Framework , the target runs with the following warnings: 当我在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.

And then crashes with (could be unrelated): 然后崩溃(可能是无关的):

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

Is this an issue with Xcode that should be reported, or am I missing a setting somehow? 这是Xcode应该报告的问题,还是我错过了设置?

Swift Package Manager sets the following, which resolved this issue for me in another project: Swift Package Manager设置了以下内容,它在另一个项目中为我解决了这个问题:

SWIFT_FORCE_DYNAMIC_LINK_STDLIB = YES
SWIFT_FORCE_STATIC_LINK_STDLIB = NO

Note that the search path was set to: 请注意,搜索路径设置为:

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

In your "Command Line Tool" Target.. set the following... 在您的“命令行工具”目标..设置以下...

LD_RUNPATH_SEARCH_PATHS = @executable_path

(Or as Xcode calls them, " Runtime Search Paths ") Setting this, the @rpath , in essence , says.. "hey, look in whatever folder the 'tool' is running in" for the dynamically loadable libs. (或者Xcode称之为“ Runtime Search Paths ”)设置这个, @rpath实质上是说......“嘿,看看'工具'运行的任何文件夹”对于可动态加载的库。 (In this case it will be your build folder. (在这种情况下,它将是您的build文件夹。

Other useful @rpath combinations involve similarly relative paths to the executable (which may also be a library or framework binary, in some cases), via @loader_path . 其它有用的@rpath组合涉及到可执行类似的相对路径(其也可以是库或框架二进制的,在某些情况下),经由@loader_path Say if the lib was bundled within a framework.. It may require the LD_RUNPATH_SEARCH_PATHS of @loader_path/Frameworks , etc. 如果说的lib是一个框架内捆绑的。它可能需要LD_RUNPATH_SEARCH_PATHS@loader_path/Frameworks等。

The above worked for me. 以上对我有用。 the two user build flags and then setting the following in runtime search paths. 两个用户构建标志,然后在运行时搜索路径中设置以下内容。

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

暂无
暂无

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

相关问题 在Swift中终止macOS命令行工具的子进程 - Terminate subprocesses of macOS command line tool in Swift 构建具有关联Swift库的Swift命令行工具时,为什么要嵌入框架? - When building a Swift command-line tool with associated Swift library why is the Framework being embedded? Cocoapods + 命令行工具 - dyld:库未加载:@rpath/Realm.framework/Versions/A/Realm - Cocoapods + Command Line Tool - dyld: Library not loaded: @rpath/Realm.framework/Versions/A/Realm 在Swift命令行工具中使用CocoaLumberjack会引发运行时错误:dyld:库未加载:@ rpath / libswiftAppKit.dylib - Using CocoaLumberjack in Swift command line tool throws runtime error: dyld: Library not loaded: @rpath/libswiftAppKit.dylib macOS Big Sur 上 Swift 命令行工具的 EventKit 权限问题 - EventKit permission problems for Swift Command Line Tool on macOS Big Sur 在Swift中从Cocoa App运行终端命令失败:“未找到命令”,但在Swift中使用命令行工具运行 - Running terminal commands from Cocoa App in Swift failing: “command not found” but works using Command Line Tool in swift 无法在 macOS 11.6 (Big Sur) 上的 swift gui 应用程序中发送击键 - “命令行工具”有效 - Cannot send a keystroke in swift gui application on macOS 11.6 (Big Sur) - "Command Line Tool" works 在macOS命令行工具项目中读取文件 - Read a file in a macOS Command Line Tool project 为 MacOS 命令行工具设置应用程序组? - Setup an App Group for MacOS command line tool? 带有OpenCV动态框架的Swift框架,未加载库 - Swift Framework with OpenCV Dynamic Framework, Library not loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM