Post not yet marked as solved
Post marked as unsolved with 0 replies, 270 views
macOS Sonoma 14.4
Xcode 15.3
Hi,
I'm experimenting with C++/Swift interop and am following the official documentation, especially the section "Using Swift APIs of Imported Framework Target".
I'm able to call Swift code from C++ when both Swift and C++ source files belong to the same app bundle or framework target, by importing the -Swift.h header.
However, I'm not able to import the Swift code from a framework using a different C++ target.
This is my test project setup:
testApp is my app bundle and subprocesses is my framework, containing the auto-generated and unchanged subprocesses.h and some example swift code with a single public function. The subprocesses framework is added as a dependency to testApp and the framework has the C++ interoperability enabled.
But when I try to import the auto-generated -Swift.h in main.cpp, it doesn't show up.
What do I need to do so that I can call Swift framework code in a different C++ target? I think I've done everything according to the documentation.
Thanks!
Addendum
I've also experimented with Apple's Xcode example projects. The "Mixing Languages in an Xcode project" (Link) works as expected. I was able to add a command line app target, and when I add the Fibonacci framework as a dependency, I'm able to use #include <Fibonacci/Fibonacci-Swift.h> and access the Swift API.
However, the second of Apple's examples, "Calling APIs Across Language Boundaries" (Link) fails to compile out of the box (No member named 'createForest' in 'ForestBuilder::MagicForest').