[英]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.