Swift Package Manager:软件更新后静态构建失败

时间:2019-06-02 12:15:43

标签: swift xcode swift-package-manager

问题描述

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

详细信息

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

我正在尝试构建 static 构建。只需尝试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 -version

在命令行中返回:

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

2 个答案:

答案 0 :(得分:0)

由于ABI的稳定性,Swift 5.0在Apple平台上不再支持静态链接。因此,如果您删除-Xswiftc -static-stdlib并且代码是有效的Swift 5.0,则构建应该可以正常工作。

答案 1 :(得分:0)

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

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