Swift/C++ interop: missing -Swift.h header for framework

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').

Answered by DTS Engineer in 50641025
Accepted Answer

@eskimo thanks for linking my original post. I've just posted the solution there as well. If Apple people are also reading it there, I can delete this post.

No need to delete stuff. It's actually good to have it here so that folks can follow the link.

I have the same question: No member named 'createForest' in 'ForestBuilder::MagicForest', did U solve this ?

Swift/C++ interop: missing -Swift.h header for framework
 
 
Q