Swift 包管理器:软件更新后静态构建失败

Swift Package manager : static build failing after software updates

问题描述

自从我更新 Xcode 后,我正在处理的一个项目没有构建。 请注意,我正在使用 swift 构建(而不是 Xcode)构建可执行文件。

详情

失败的命令是: swift build -Xswiftc -static-stdlib -Xswiftc -DDEBUG

我正在尝试构建 静态。只要尝试 swift build,就可以了。

错误

我只复制错误输出的开头(其余太长):

ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift_static/macosx'
ld: warning: Could not find auto-linked library 'swiftFoundation'
ld: warning: Could not find auto-linked library 'swiftDarwin'
ld: warning: Could not find auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find auto-linked library 'swiftIOKit'
ld: warning: Could not find auto-linked library 'swiftQuartzCore'
ld: warning: Could not find auto-linked library 'swiftCore'
ld: warning: Could not find auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find auto-linked library 'swiftObjectiveC'
ld: warning: Could not find auto-linked library 'swiftDispatch'
ld: warning: Could not find auto-linked library 'swiftCoreData'
ld: warning: Could not find auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find auto-linked library 'swiftXPC'
ld: warning: Could not find auto-linked library 'swiftMetal'
ld: warning: Could not find auto-linked library 'swiftAppKit'
ld: warning: Could not find auto-linked library 'swiftCoreImage'
Undefined symbols for architecture x86_64:

Package.swift

请注意,为了匿名起见,我已经重命名了项目和库名称。

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "PROJECT",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "../Lib1", .branch("master")),
        .package(url: "../Lib2", .branch("master")),
        .package(url: "../Lib3", .branch("master")),
        .package(url: "../Lib4", .branch("master")),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "PROJECT",
            dependencies: ["Lib1", "Lib2", "Lib3", "Lib4"]),
    ]
)

Swift更新后的版本

运行

swift -version

在命令行中 returns :

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.2.0

Swift 由于 ABI 稳定性,5.0 不再支持 Apple 平台上的静态链接。因此,如果您删除 -Xswiftc -static-stdlib 并且代码有效 Swift 5.0.

,构建应该可以正常工作

新版本的 MacOS 不支持静态构建。在这里查看答案:

https://forums.swift.org/t/swift-package-manager-static-build-failing-after-software-updates/25694