[英]Using CocoaLumberjack in Swift command line tool throws runtime error: dyld: Library not loaded: @rpath/libswiftAppKit.dylib
I have a command line tool written in Swift. 我有一个用Swift编写的命令行工具。 I use Lumberjack in other, related apps, so I would like to get it working in this one.
我在其他相关应用程序中使用了Lumberjack,因此我希望它能够在此应用程序中运行。 The command line tool does not import AppKit.
命令行工具不会导入AppKit。 According to the DDTTYLogger.h file, if DD_CLI is defined, custom color defs.
根据DDTTYLogger.h文件,如果定义了DD_CLI,则自定义颜色定义。 (CLIColor.h/m) are imported, rather than AppKit/NSColor.h, so it seems that I shouldn't be getting the error.
(CLIColor.h / m)是导入的,而不是AppKit / NSColor.h,所以看来我不应该收到此错误。
So far, I have tried adding –DDD_CLI to the Swift Compiler, Other Swift Flags. 到目前为止,我已经尝试将–DDD_CLI添加到Swift编译器Other Swift Flags。 I also tried adding CLIColor.m to the build.
我还尝试将CLIColor.m添加到构建中。 I am at a loss... Anyone have experience with this, or have some other things I can try?
我很茫然……有人对此有经验,或者有其他可以尝试的东西吗?
I appreciate your feedback. 感谢您的反馈。
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. 我使用在OS X 10.11.6上运行的Xcode 8 beta遇到了这个问题,尽管我遇到了一个特定的问题,但调试方法在所有情况下都是相同的。
The otool
command can be used to see exactly where the linker was instructed to look for library files, along with their names. otool
命令可用于确切地指示链接器在何处查找库文件及其名称。
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). 对我来说,
otool -l {executable_path}
表明它正在/System/Library/PrivateFrameworks/swift
查找文件,该文件是在10.12(Sierra)中引入的。 Since I'm running 10.11.6, this is a showstopper. 由于我运行的是10.11.6,因此这是一个热门话题。 (And a known bug in Xcode 8 beta)
(还有Xcode 8 beta中的一个已知错误)
Looking at the otool
output, there are two things to see: 查看
otool
输出,有两件事要看:
LC_LOAD_DYLIB
commands, which show the names of the libraries to include. LC_LOAD_DYLIB
命令,显示要包括的库的名称。 @rpath/
which is a shortcut used to find files. @rpath/
作为前缀,这是用于查找文件的快捷方式。 LC_RPATH
which shows the search path for library names prefixed with @rpath/
. LC_RPATH
,显示以@rpath/
开头的库名称的搜索路径。 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). 您可以通过在构建设置的“
Other Linker Flags
字段中包含LC_RPATH
-rpath {absolute_path_to_files}
来更改LC_RPATH
(这是使您重新编译的临时解决方法)。 For me that meant setting the rpath to the library files in the appropriate SDK's files, not /System
. 对我来说,这意味着将rpath设置为适当的SDK的文件中的库文件,而不是
/System
。 Doing this is fraught with peril for a bunch of reasons. 这样做有很多原因, 充满了危险 。 So don't forget to undo it.
因此,不要忘记撤消它。
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. 使用
otool
您可以查看实际发生的情况,因此可以智能地修改“ Runpath Search Paths
构建设置,以跳到一个或两个目录,并查看它如何影响链接器的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.