Problem with "Getting Started" project

I tried to follow the "Getting Started with C++ Interop" guide, but I can't get past "error: public headers ("include") directory path for 'CxxTest' is invalid or not contained in the target".

Any idea what I'm missing?

module.modulemap:

module CxxTest {
  header "CxxTest.hpp"
  requires cplusplus
}

Folder structure and Package.swift:

Many thanks! :)

Can you try moving module.modulemap and CxxTest.hpp into a new subdirectory called include? (Sources/CxxTest/include)

Oh that works, thanks! I'm curious, what's the reason for that?

AFAIU an implicit include subdirectory is always required when building targets that contain module.modulemap with SwiftPM. We do need the "Getting Started" document for C++ to be updated to reflect that.

Ah interesting! I'm short on time, but quickly put together an issue on GH.

2 Likes

I have just added Update C++ Interop Getting Started Guide · Issue #63461 · apple/swift · GitHub which seems to be necessary to make it compile.

Unfortunately I could only compile it as a Swift Package from the command line. When I open that Swift Package in Xcode (via xed .), for some reason, Xcode seems to complain with

error: Driver threw unknown argument: '-cxx-interoperability-mode=swift-5.9' without emitting errors. (in target 'Swift-CANyonero' from project 'Swift-CANyonero')

although I downloaded and activated the latest Xcode toolchain from the 5.9/development branch.

How can I fix that?

1 Like