Undefined symbols for architecture arm64:
"Swift.Array.init() -> [A]", referenced from:
foo() in foo.cpp.o
"type metadata accessor for Swift.Array", referenced from:
foo() in foo.cpp.o
foo() in foo.cpp.o
"type metadata for Swift.Float", referenced from:
foo() in foo.cpp.o
foo() in foo.cpp.o
ld: symbol(s) not found for architecture arm64
On Windows, I would suspect a missing toolchain /bin .DLL, but on Mac, I am surprised to see this.
Is there perhaps some .dylib / library that must be linked against to gain access to swift::String and swift::Array?
The project is otherwise healthy, with large numbers of Swift types being used happily from the C++ code. It's just swift::Array and swift::String causing grief!
Toolchain (Mac): swift-6.0.1-RELEASE
Clang (Mac): Apple clang version 16.0.0 (clang-1600.0.26.3)
Potentially related: Attempting to work with an std::string generated in Swift, in C++, yields an EXCEPTION_ACCESS_VIOLATION on Windows, though it does appear to work well on Mac.
I feel like there might be some piece of the puzzle I am missing, with respect to getting stable std::string / swift::String / std::Array use in C++ interop. Keen to hear ideas from any wise members of the forum!
Could you try to link explicitly against libswiftCore.tbd (on macOS) and swiftCore.lib on Windows? That's the library that defines those missing symbols.
@egor.zhdan thank you for the reply and suggestion. I was not able to find libswiftCore.tbd anywhere in swift-6.0.1-RELEASE.xctoolchain, but I did find a libswiftCore.dylib in the macOS directory, and I understand them to be equivalent.
Linking against libswiftCore.dylib resolved the linker errors on Mac, and swiftCore.lib on Windows.
In hindsight this seems obvious - I appreciate your help.