在Swift命令行工具中使用CocoaLumberjack会引发运行时错误:dyld:库未加载:@ rpath / libswiftAppKit.dylib [英] Using CocoaLumberjack in Swift command line tool throws runtime error: dyld: Library not loaded: @rpath/libswiftAppKit.dylib

查看:163
本文介绍了在Swift命令行工具中使用CocoaLumberjack会引发运行时错误:dyld:库未加载:@ rpath / libswiftAppKit.dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Swift编写的命令行工具。我在其他相关应用程序中使用了Lumberjack,因此我希望它可以在此应用程序中运行。命令行工具不会导入AppKit。根据DDTTYLogger.h文件,如果定义了DD_CLI,则自定义颜色定义。 (CLIColor.h / m)而不是AppKit / NSColor.h是导入的,因此看来我不应该得到此错误。

I have a command line tool written in Swift. I use Lumberjack in other, related apps, so I would like to get it working in this one. The command line tool does not import AppKit. According to the DDTTYLogger.h file, if DD_CLI is defined, custom color defs. (CLIColor.h/m) are imported, rather than AppKit/NSColor.h, so it seems that I shouldn't be getting the error.

到目前为止,我已经尝试将–DDD_CLI添加到Swift编译器Other Swift Flags。我还尝试将CLIColor.m添加到构建中。我不知所措...任何有经验的人,或者有其他可以尝试的东西?

So far, I have tried adding –DDD_CLI to the Swift Compiler, Other Swift Flags. I also tried adding CLIColor.m to the build. I am at a loss... Anyone have experience with this, or have some other things I can try?

感谢您的反馈。

推荐答案

我使用运行在OS X 10.11.6上的Xcode 8 beta遇到了这个问题,尽管我遇到了一个特定的问题,但是调试该问题的方法是所有情况下的相同

I ran into this using the Xcode 8 beta, running on OS X 10.11.6, and though I had a vary specific problem, the way to debug this is the same for all cases.

otool 命令可用于查看恰好,其中指示链接程序查找库文件及其名称。

The otool command can be used to see exactly where the linker was instructed to look for library files, along with their names.

对于我来说, otool- l {executable_path} 表明它正在寻找在10.12(Sierra)中引入的 / System / Library / PrivateFrameworks / swift 中的文件。由于我运行的是10.11.6,因此这是一个热门话题。 (还有Xcode 8 beta中的一个已知错误)

For me, otool -l {executable_path} showed that it was looking for files in /System/Library/PrivateFrameworks/swift which was introduced in 10.12 (Sierra). Since I'm running 10.11.6, this is a showstopper. (And a known bug in Xcode 8 beta)

otool 输出,有两件事要看:

Looking at the otool output, there are two things to see:


  1. LC_LOAD_DYLIB 命令,显示要包含的库的名称。
    load命令可能显示文件的绝对路径,或者可以使用 @rpath / 作为前缀,这是用于查找文件的快捷方式。

  2. LC_RPATH 显示以 @rpath /

  1. LC_LOAD_DYLIB commands, which show the names of the libraries to include.
    The load command might show an absolute path to the file, or could be prefixed with @rpath/ which is a shortcut used to find files.
  2. LC_RPATH which shows the search path for library names prefixed with @rpath/.

您可以通过添加<$ c来更改 LC_RPATH $ c> -rpath {absolute_path_to_files} 在构建设置的 Other Linker Flags 字段中(作为临时工作-around让您重新编译)。对我来说,这意味着将rpath设置为适当的SDK文件中的库文件,而不是 / System 中的文件。出于多种原因,这样做充满了危险。因此,请不要忘记撤消它。

You can alter the LC_RPATH by including -rpath {absolute_path_to_files} in the Other Linker Flags field in your build settings (as a temporary work-around to get you compiling again). For me that meant setting the rpath to the library files in the appropriate SDK's files, not /System. Doing this is fraught with peril for a bunch of reasons. So don't forget to undo it.

如果您仅在构建层次结构方面遇到问题,可以使用更简单的方法。使用 otool 您可以查看实际情况,因此您可以智能地修改 Runpath搜索路径构建设置以跳转一个或两个目录,看看如何影响链接器的输出。

You can use a lighter approach if you're just having issues with build hierarchies. Using otool you can see what is actually happening, so you can intelligently modify the Runpath Search Paths build setting to jump up a directory, or two and see how that affects the linker's output.

这篇关于在Swift命令行工具中使用CocoaLumberjack会引发运行时错误:dyld:库未加载:@ rpath / libswiftAppKit.dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆