我正在使用 Swift Package Manager 构建一个命令行工具,使用 Ink作为依赖项。
我正在关注this article by John Sundell作为引用,我设法使用 swift build -c release
编译和运行该工具。
我还使用swift packagegenerate-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 项目设置才能使其正常工作吗?
最佳答案
经过验证的解决方案
不要不要运行swift packagegenerate-xcodeproj
。
相反,只需直接在 Xcode 中打开 Package.swift
即可。
这样,所有包都是静态链接的。
关于swift - 从 SPM 中 Xcode 生成的项目出现运行时错误(dyld : Library not loaded, 不兼容的库版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59172178/