避免自动快速链接框架 [英] Avoid automatic framework linking in swift

查看:34
本文介绍了避免自动快速链接框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 示例项目,其中包含一个主要目标 (LinkerTests)和一个依赖的动态框架(Dynamic).

I have an example project consisting of a main target (LinkerTests) and a dependent dynamic framework (Dynamic).

如果你运行项目,你会看到如下dyld二进制加载:

If you run the project, you will see the following dyld binary load:

dyld: loaded: {DerivedDataPath}/Build/Products/Debug-iphonesimulator/Dynamic.framework/Dynamic

这个 dyld 二进制加载是由于 AppDelegate.swift 中的 import Dynamic 而发生的,尽管有以下情况:

This dyld binary load happens due to import Dynamic in AppDelegate.swift despite of the following:

  1. Link Binary With Libraries 构建阶段为空
  2. CLANG_MODULES_AUTOLINK 设置为 false
  1. Link Binary With Libraries build phase is empty
  2. CLANG_MODULES_AUTOLINK is set to false

我需要实现的是避免这种自动隐式链接.这可能吗?提前致谢!

What I need to achieve is avoiding this automatic implicit linking. Is this possible? Thanks in advance!

相关问题:难道我们不需要不再将框架链接到 XCode 项目?

推荐答案

显然这个功能叫做自动链接.Swift 编译器会隐式发出额外的链接器标志,用于链接源代码所依赖的所有模块 (import Dynamic).

Apparently this feature is called autolinking. Swift compiler implicitly emits additional linker flags that links in all the modules the source code depends on (import Dynamic).

没有办法完全禁用它.但是有一个私有编译器标志允许您禁用单个框架的自动链接:swiftc -disable-autolink-framework .

There is no way to disable this entirely. But there is a private compiler flag that allows you to disable autolinking for a single framework: swiftc -disable-autolink-framework <framework>.

一些参考:https://gist.github.com/zrzka/c89705ff634ea01aebc1https://github.com/niw/automatic_linking_tool/blob/master/README.md

我很确定你可以将 -v 附加到 swiftc 并且它会将所有底层调用打印为命令.希望您也能看到链接器调用.

I’m pretty sure you can append -v to swiftc and it will print all underlying invocations as commands. Hopefully you’ll be able to see the linker invocations as well.

您应该将私有标志包装在两个 -Xfrontend 标志中以允许使用它:

You should wrap the the private flag inside two -Xfrontend flags to allow it to be used:

OTHER_SWIFT_FLAGS = "-Xfrontend -disable-autolink-framework -Xfrontend Dynamic"

要使其生效,您仍必须在 Apple Clang - 语言 - 模块下设置自动链接框架否.

For this to take effect you must still set Link Frameworks Automatically No under Apple Clang - Language - Modules.

这篇关于避免自动快速链接框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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