I have a Package that combines a Swift target and several C++ binary targets. I have a project that imports the Package as a module. When I try to build my project in Xcode, it gives me errors that it cannot resolve the C++ procedure calls from within the Swift target files of the package. The header files for the C++ procedures are stored within one of binary targets.
The purpose of the package is to bundle a set of Swift bindings for a C++ API and make it as convenient as possible for other developers to use those bindings. The bindings comprise the Swift target of the package. The package supports both macOS and iOS, and is composed of the bindings along with several xcframeworks and a set of test modules. Each xcframework encapsulates a pair of precompiled C++ dylibs, one for macOS and another for iOS. The header files are built into one of the xcframeworks.
I use Xcode to add the package to my project via File->Add Packages... And then I add the package to Targets->Frameworks, Libraries and Embedded Content. The package also includes a bridging header, which I specify in Targets->Build Settings->Swift Compiler General->Objective-C Bridging Header.
Here's my package:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "BrainFlow",
platforms: [
.macOS(.v10_15), .iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(name: "BrainFlow",
targets: ["BrainFlow", "BoardController", "DataHandler", "MLModule", "BrainBitLib"])
],
dependencies: [
.package(name: "swift-numerics",
url: "https://github.com/apple/swift-numerics.git", .upToNextMajor(from: "1.0.0"))
],
targets: [
.target(
name: "BrainFlow",
dependencies: [.product(name: "Numerics", package: "swift-numerics"),
.target(name: "BoardController")]
),
.binaryTarget(
name: "BoardController",
path: "BoardController.xcframework" // the header files are located within this target
),
.binaryTarget(
name: "DataHandler",
path: "DataHandler.xcframework"
),
.binaryTarget(
name: "MLModule",
path: "MLModule.xcframework"
),
.binaryTarget(
name: "BrainBitLib",
path: "BrainBitLib.xcframework"
),
.testTarget(
name: "BrainFlowTests",
dependencies: ["BrainFlow", .product(name: "Numerics", package: "swift-numerics")],
sources: ["BoardShimTests.swift",
"BrainFlowCItests.swift",
"BrainFlowTests.swift",
"DataFilterTests.swift"]
)
]
)
And here's a screenshot of the package layout and an example of the errors:
Thanks in advance,
Scott