I've created a swift package that has multiple targets. For example:
.target( name: "LibrarySwift", dependencies: [ "LibraryObjC"]), .target( name: "LibraryObjC", dependencies: ["LibraryCPP"], cxxSettings: [ .headerSearchPath("../../LibraryCPP/")]), .target( name: "LibraryCPP", cxxSettings: [ .headerSearchPath("../../LibraryCPP/")]), .testTarget( name: "LibrarySwiftTests", dependencies: ["LibrarySwift"]),
With the test target commented out, everything builds as expected, I can call the Objective-C functions that wrap the C++ library functions within LibrarySwift, etc. However, when I enable the test target that uses
LibrarySwift I suddenly get a bunch of Undefined Symbol warnings in the test target for LibraryCPP objects.
Searching around I've found a couple of similar issues where the problem was SwiftPM considering a
main.swift file as an executable. The resolution was to remove or package that main.swift separately allowing the source to be treated as a library. But I'm not sure how to approach and troubleshoot this with a C++ library and if it's a related or entirely different issue.
Edit: I was able to verify this same issue also happens while importing the LibrarySwift into an example project (e.g. iOS)