我正在使用 Swift 包管理器为现有的 C 库创建一个 Swift 包装器。我认为我已经正确构建了所有内容,但是在创建和构建 Xcode 项目时出现错误。我已经尝试了我能找到的一切,但没有运气。正式让我难过。
以下是项目当前状态的链接:https ://github.com/JKcompute/Camiitool/tree/stackpost
这是我的 Package.swift
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "CamiitoolPackage",
products: [
.library(name: "Camiitool", targets: ["Camiitool"]),
.library(name: "amiitoolSwift", targets: ["amiitoolSwift"]),
],
dependencies: [
],
targets: [
.target(
name: "amiitoolSwift",
dependencies: [
"Camiitool"
],
path: "./Sources/amiitoolSwift"
),
.target(
name: "Camiitool",
dependencies: [
"mbedtls"
],
path: "./Sources/Camiitool",
exclude: [
"mbedtls",
"LICENSE"
],
resources: [
.copy("."),
]
),
.target(
name: "mbedtls",
dependencies: [],
path: "./Sources/Camiitool/mbedtls",
exclude: [
"./mbedtls/yotta",
"./mbedtls/visualc",
"LICENSE"
],
resources: [
.copy("."),
]
),
.testTarget(
name: "amiitoolSwiftTests",
dependencies: ["amiitoolSwift"]
)
]
)
所以我这里的 Camiitool 是 C 库 Amiitool。Amiitool 依赖于 mbedtls。所以我有一个针对 mbedtls、Camiitool 的目标,然后我也有一个针对 amiitoolSwift 的目标,我计划拥有我的 swift API。
这是来自 amiitoolSwift 目标的我的 swift 文件。注意:它现在非常基本,仅用于测试。
import Foundation
import Camiitool
public class Amii {
var someString = "test"
public init() {
someString = "initialized"
}
public func printTest() {
print(someString)
}
public func methodJustForTesting() {
print(someString)
let cString: UnsafePointer<CChar> = Camiitool.nfc3d_version_fork()
print(String(cString: cString))
}
}
问题是,当我构建时,我收到 Camiitool 的“未找到框架”错误。
> Ld /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Products/Debug/amiitoolSwift.framework/Versions/A/amiitoolSwift normal (in target 'amiitoolSwift' from project 'CamiitoolPackage')
cd /Users/ME/GIT/PERSONAL/Amiibo/backup-wip/Camiitool
/Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.10 -dynamiclib -isysroot /Applications/Xcode_12.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Products/Debug -F/Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Products/Debug -F/Applications/Xcode_12.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -filelist /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Intermediates.noindex/CamiitoolPackage.build/Debug/amiitoolSwift.build/Objects-normal/x86_64/amiitoolSwift.LinkFileList -install_name @rpath/amiitoolSwift.framework/Versions/A/amiitoolSwift -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker /Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -Xlinker -object_path_lto -Xlinker /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Intermediates.noindex/CamiitoolPackage.build/Debug/amiitoolSwift.build/Objects-normal/x86_64/amiitoolSwift_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-link-runtime -L/Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Intermediates.noindex/CamiitoolPackage.build/Debug/amiitoolSwift.build/Objects-normal/x86_64/amiitoolSwift.swiftmodule -framework Camiitool -framework mbedtls -Xlinker -dependency_info -Xlinker /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Intermediates.noindex/CamiitoolPackage.build/Debug/amiitoolSwift.build/Objects-normal/x86_64/amiitoolSwift_dependency_info.dat -o /Users/ME/Library/Developer/Xcode/DerivedData/CamiitoolPackage-fjhqfruljmetilfuiykpzwhzobkc/Build/Products/Debug/amiitoolSwift.framework/Versions/A/amiitoolSwift
ld:找不到框架 Camiitool clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
我试图解决这个问题的任何事情似乎都会产生相同错误的一些不同版本。例如“Module not found Camiitool”,或者我找到了 Camiitool,但随后我在方法调用 (nfc3d_version_fork) 上收到错误,表明该方法不存在。
最后一点:我的项目的当前状态基于我发现的这个示例:https ://github.com/RoaringBitmap/SwiftRoaring 这与我正在做的基本相同,除了没有子模块。我已经取消了这个项目,并且能够很好地构建和运行它。我已经比较了项目之间的所有设置,我没有注意到任何差异。这导致我最终在这里发帖。
运行 MacOS 10.15.7、Xcode 12.0