首页 > 解决方案 > 包产品“MyLibrary”不能用作此目标的依赖项,因为它使用了不安全的构建标志

问题描述

我正在尝试为我的库添加 SPM 支持。我需要为unsafeFlags我的库的一个目标定义(为了将 Swift 代码导入到 Objective-C++ 中):

.target(name: "MyLibrary",
        dependencies: ["MyOtherTarget"],
        cSettings: [
            .unsafeFlags(["-fmodules", "-fcxx-modules"]),
            .define("BUILDING_FOR_SPM")
        ]
),

生成的包构建。但是当我将它导入主机应用程序时,它无法构建,因为

The package product 'MyLibrary' cannot be used as a dependency of this target because it uses unsafe build flags.

根据这篇文章和相应的拉取请求,该问题已在 Swift 4 中得到解决。我使用的是 Xcode 12.5 和 Swift 5。

发生什么了?

标签: iosmacosswift-package-manager

解决方案


.unsafeFlags不允许使用版本指定的依赖项。解决方法是使用提交哈希指定版本。

在https://forums.swift.org/t/override-for-unsafeflags-in-swift-package-manager/45273上有关 monorepos 的详细讨论和另一种解决方法


推荐阅读