简体   繁体   中英

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.

The problem occurs in this example , which has a Package.swift file that looks like this:

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.

The issue happens when I run 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).

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.

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.

Here is 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"
            ]
        )
    ]
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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