[英]Problem with Frameworks in Command Line Tool
Before everyone starts throwing other stack-overflow and forum posts at me: I looked at them all. 在所有人开始向我抛出其他堆栈溢出和论坛帖子之前:我已经全部查看了。 None of them are helping. 他们都没有帮助。
I have a simple cmd tool called swizzler
and want to embed the SwizzleSrc
framework in it. 我有一个名为swizzler
的简单cmd工具,并希望将SwizzleSrc
框架嵌入其中。 I have followed all the tutorials and stack overflows with no luck. 我已经按照所有的教程进行了学习,并且没有运气而导致堆栈溢出。 Here is what I am getting. 这就是我得到的。
Build 建立
2019-02-07 19:22:46.785680-0500 Terminal[67444:11837029] flock failed to lock maps file: errno = 35
2019-02-07 19:22:46.786939-0500 Terminal[67444:11837029] flock failed to lock maps file: errno = 35
Run 跑
Last login: Thu Feb 7 19:21:08 on ttys018
NAME-iMac:~ NAME$ /Users/NAME/Library/Developer/Xcode/DerivedData/swizzler-aslysekmorknabdslxbxfaeuiztk/Build/Products/Debug/swizzler ; exit;
dyld: Library not loaded: @rpath/SwizzleSrc.framework/Versions/A/SwizzleSrc
Referenced from: /Users/NAME/Library/Developer/Xcode/DerivedData/swizzler-aslysekmorknabdslxbxfaeuiztk/Build/Products/Debug/swizzler
Reason: image not found
Abort trap: 6
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
Can someone please help? 有人可以帮忙吗? I have been trying for days with no avail. 我已经尝试了好几天都无济于事。
To fix your issue we need to change how Xcode handles Swift Command Line Tool targets by default, specifically the linking convention against the Swift standard libraries. 为了解决您的问题,我们需要默认更改Xcode处理Swift 命令行工具目标的方式,特别是针对Swift标准库的链接约定。
We need to: 我们要:
SwizzleSrc
framework 将Swift标准库嵌入到SwizzleSrc
框架中 swizzler
command line executable to dynamically link all Swift libraries 强制您的swizzler
命令行可执行文件动态链接所有Swift库 swizzler
executable is then able to find all needed Swift libraries (now placed in the framework target) 最后,确保您的swizzler
可执行文件能够找到所有需要的Swift库(现已放置在框架目标中) Let's get started (assumes you are using Xcode 10.1 or above): 让我们开始吧(假设您正在使用Xcode 10.1或更高版本):
This is pretty straightforward. 这很简单。 Change the following Build Settings for the SwizzleSrc
framework target: 为SwizzleSrc
框架目标更改以下构建设置 :
This is the somewhat tricky part. 这是有些棘手的部分。 Add the following User-Defined settings for the swizzler
tool target (in the Build Settings ): 为swizzler
工具目标添加以下用户定义的设置(在Build Settings中 ):
SWIFT_FORCE_DYNAMIC_LINK_STDLIB
set to YES
SWIFT_FORCE_DYNAMIC_LINK_STDLIB
设置为YES
SWIFT_FORCE_STATIC_LINK_STDLIB
set to NO
SWIFT_FORCE_STATIC_LINK_STDLIB
设置为NO
(To add a new User-Defined setting just click the +
button just below the Build Settings tab title.) (要添加新的用户定义设置,只需单击“ 构建设置”选项卡标题下方的+
按钮。)
This will ensure your command line executable will dynamically link all Swift libraries instead (ie, by default they are statically linked). 这将确保您的命令行可执行文件将改为动态链接所有Swift库(即,默认情况下它们是静态链接的)。 By the way, these exact same settings are used by the Swift Package Manager to fix a related issue. 顺便说一句,Swift软件包管理器使用这些完全相同的设置来修复相关问题。
Add the following Runpath Search Path entries for the swizzler
tool target (in the Build Settings ): 为swizzler
工具目标添加以下Runpath搜索路径条目(在Build Settings中 ):
@executable_path
@executable_path/SwizzleSrc.framework/Versions/Current/Frameworks
Now clean your build folder, rebuild again both targets, and check if this fixed your issue for good ;) 现在清理您的构建文件夹,再次重建两个目标,然后检查是否可以彻底解决您的问题;)
For further information, be sure to check the following links as well: 有关更多信息,请确保还检查以下链接:
I also created a (very!) simple Xcode project demonstrating the steps above: 我还创建了一个(非常!)简单的Xcode项目,演示了上述步骤:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.