(XCode 15 beta 6, MacOS 14.0 Beta (23A5301h))
I have two projects:
-
Swift + C++ together in an XCode project. Swift can see C++ fine, compiles and runs. No problem.
-
Swift Package with C++ library target and Swift library target with a Testing target. It uses an explicit module map (because I couldn't get the umbrella header style example to work, actually). It does not run tests.
module cxxLibrary {
header "SimpleCxxFunctions.hpp"
export *
}
- GitHub - carlynorama/CxxInteropLibrary: Project for trying out C++ Interop with Swift in the context of a Library
When I run the test, either in Xcode via the GUI diamonds or the command line with swift test I get :
Building for debugging...
ld: Undefined symbols:
_myFavoriteNumber, referenced from:
InteropLibrary.NumberMaker.currentNumber() -> Swift.Int in NumberMaker.swift.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[5/6] Linking CxxInteropLibraryPa…
error: fatalError
Package file:
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "CxxInteropLibrary",
products: [
.library(
name: "cxxLibrary",
targets: ["cxxLibrary"]),
.library(
name: "InteropLibrary",
targets: ["InteropLibrary"])
],
targets: [
.target(
name: "cxxLibrary"),
.target(
name: "InteropLibrary",
dependencies: ["cxxLibrary"]),
//swiftSettings: [.interoperabilityMode(.Cxx)]), have tried it both ways.
.testTarget(
name: "CxxInteropLibraryTests",
dependencies: ["InteropLibrary", "cxxLibrary"],
swiftSettings: [.interoperabilityMode(.Cxx)])
]
)
Neither XCode nor the VScode extension flag any problems before the build.
Before I keep banging my head against this, should I even expect this to work with XCTests? If so is there something obvious I've done wrong?
Thank you.