奇怪的 Link 命令行 Swift 测试错误(可能与 Swift 包管理器相关)

Strange Link Error With Command-Line Swift Test (May Be Swift Package Manager-Related)

我正在开发一组互连的 SPM 模块作为 test/demo,但我 运行 遇到了一个奇怪的链接器错误。

问题出现在 this example 中,它有一个 Package.swift 文件,如下所示:

import PackageDescription

let package = Package(
    name: "Package_C",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(
            name: "Package-C",
            type: .dynamic,
            targets: ["Package_C"])
    ],
    dependencies: [
        .package(name: "Package_A", url: "git@github.com:LittleGreenViper/SPMArticle-Package_A.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "Package_C",
            dependencies: [
                .product(name: "Package-A", package: "Package_A")
            ],
            path: "src"
        ),
        .testTarget(
            name: "Package_CTests",
            dependencies: [
                "Package_C"
            ],
            path: "test"
        )
    ]
)

包在 swift build 上构建良好,并且一切正常,当 运行 来自 Xcode。

当我 运行 swift test 时出现此问题。我收到以下错误:

Undefined symbols for architecture x86_64:
  "_$s9Package_CAAV6indentABSi_tcfC", referenced from:
      _$s14Package_CTests4testC0C7QuicklyyyFSSyKXEfu_ in Package_CTests.swift.o
ld: symbol(s) not found for architecture x86_64
[4/5] Linking Package_CPackageTests

看起来 Package_C 没有被链接,但一切似乎都绝对符合标准(另外,请记住其他一切都正常。swift test 是唯一失败的地方)。

应该注意 this project 工作正常,并且几乎完全相同。

我能看到的唯一区别是目录的命名约定。我真的很讨厌这成为问题,但接下来我会解决这个问题。

谁能看到我看不到的东西?

编辑添加: 我应该注意到 static/dynamic 似乎不是问题所在。我得到同样的错误,即使我将 Package_C 更改为静态。

呃。看起来问题是需要遵循命名约定。

我是从这个切换过来的:

为此:

它开始工作了。没有更改文件内容(除了从 Package.swift 文件中删除两个 path 参数)。

这里是the new Package.swift file:

// swift-tools-version:5.2

import PackageDescription

let package = Package(
    name: "Package_C",
    platforms: [
        .iOS(.v11),
        .tvOS(.v11),
        .macOS(.v10_14),
        .watchOS(.v5)
    ],
    products: [
        .library(
            name: "Package-C",
            type: .dynamic,
            targets: ["Package_C"])
    ],
    dependencies: [
        .package(name: "Package_A", url: "git@github.com:LittleGreenViper/SPMArticle-Package_A.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "Package_C",
            dependencies: [
                .product(name: "Package-A", package: "Package_A")
            ]
        ),
        .testTarget(
            name: "Package_CTests",
            dependencies: [
                "Package_C"
            ]
        )
    ]
)