简体   繁体   English

命令行 Swift 测试出现奇怪的链接错误(可能是 Swift Package 管理器相关)

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

I'm developing a set of interlinked SPM modules as a test/demo, and I've run into a strange linker error.我正在开发一组相互关联的 SPM 模块作为测试/演示,我遇到了一个奇怪的 linker 错误。

The problem occurs in this example , which has a Package.swift file that looks like this:此示例中出现问题,该示例具有如下所示的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"
        )
    ]
)

The package builds fine with swift build , and everything works great, when run from Xcode. package 与swift build良好,从 Xcode 运行时一切正常。

The issue happens when I run swift test .当我运行swift test时会发生此问题。 I get the following error:我收到以下错误:

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

It looks like Package_C is not being linked in, but everything appears to be absolutely kosher (also, remember that everything else works fine. swift test is the only place this fails).看起来Package_C没有被链接,但一切似乎都是绝对的(另外,请记住,其他一切都很好swift test是唯一失败的地方)。

It should be noted that this project works fine, and does almost exactly the same thing.应该注意的是,这个项目运行良好,并且几乎完全相同。

The only difference that I can see, is the naming conventions of the directories.我能看到的唯一区别是目录的命名约定。 I'd really hate for that to be the issue, but I'll mess around with that, next.我真的很讨厌这个问题,但接下来我会解决这个问题。

Can anyone see what I can't see?谁能看到我看不到的东西?

EDITED TO ADD: I should note that the static/dynamic thing doesn't seem to be the issue.编辑添加:我应该注意到静态/动态的东西似乎不是问题。 I get the same error, even when I change Package_C to static.即使我将Package_C更改为 static,我也会遇到同样的错误。

Ugh.啊。 Looks like the issue is that the naming convention needs to be followed.看起来问题是需要遵循命名约定。

I switched from this:我从这个切换:

在此处输入图像描述

To this:对此:

在此处输入图像描述

and it started working.它开始工作了。 No file contents (other than removing the two path arguments from the Package.swift file) were changed.没有文件内容(除了从Package.swift文件中删除两个path arguments 之外)被更改。

Here is the new Package.swift file :这是新的 Package.swift 文件

// 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"
            ]
        )
    ]
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM