SPM由Xcode生成的项目发生运行时错误(dyld:库未加载,库版本不兼容)

时间:2019-12-04 08:54:56

标签: swift xcode

我正在使用Ink作为依赖项,使用Swift Package Manager构建命令行工具。

我正在跟踪this article by John Sundell供参考,我设法获得了可以用swift build -c release进行编译和运行的工具。

我还使用swift package generate-xcodeproj生成了一个相应的Xcode项目,以便可以使用调试器并更有效地工作。

但是,每当我尝试从Xcode运行我的工具时,都会出现此错误:

dyld: Library not loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Ink.framework/Versions/A/Ink
  Referenced from: /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox
  Reason: Incompatible library version: HIToolbox requires version 1.0.0 or later, but Ink provides version 0.0.0
Program ended with exit code: 9

作为参考,这是我的Package.swift

import PackageDescription

let package = Package(
    name: "SwiftSiteGen",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
      .package(
          url: "https://github.com/johnsundell/files.git",
          from: "4.0.0"
      ),
      .package(
          url: "https://github.com/johnsundell/Ink.git",
          from: "0.1.3"
      ),
    ],
    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: "SwiftSiteGen",
            dependencies: ["SwiftSiteGenCore"]),
        .target(name: "SwiftSiteGenCore",
                dependencies: ["Files", "Ink"]),
        .testTarget(
            name: "SwiftSiteGenTests",
            dependencies: ["SwiftSiteGen"]),
    ]
)

我正在macOS 10.14.4的Xcode 11.2.1上运行。

由于运行swiftc build可以正常工作,所以我认为问题在于Xcode尝试使用动态框架而不是静态库。可能是相关的问题here

要进行这项工作,是否需要更改一些Xcode项目设置?

1 个答案:

答案 0 :(得分:1)

已验证的解决方案

不要运行swift package generate-xcodeproj

相反,只需直接在Xcode中打开Package.swift

那样,所有软件包都是静态链接的。