Swift is currently at 6.0.1, and C++ interoperability seems to work on Windows. Until it turns out that it doesn't.
The same simple source code:
@_cdecl("meaningOfLife")
public func meaningOfLife() -> Int {
return 42
}
The same build command:
swiftc dynamicLibrary.swift -emit-library -cxx-interoperability-mode=default
And voila! Dynamic library is created. Unless you add import Foundation
to your code. In this case things are broken again:
Compiler output
<module-includes>:1:10: note: in file included from <module-includes>:1:
1 | #include "_FoundationCShims.h"
| `- note: in file included from <module-includes>:1:
2 |
C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_FoundationCShims.h:17:10: note: in file included from C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_FoundationCShims.h:17:
15 |
16 | #include "_CShimsTargetConditionals.h"
17 | #include "_CStdlib.h"
| `- note: in file included from C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_FoundationCShims.h:17:
18 | #include "CFUniCharBitmapData.inc.h"
19 | #include "CFUniCharBitmapData.h"
C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_CStdlib.h:23:2: note: in file included from C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_CStdlib.h:23:
21 |
22 | #if __has_include(<ctype.h>)
23 | #include <ctype.h>
| `- note: in file included from C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_CStdlib.h:23:
24 | #endif
25 |
<unknown>:0: error: could not build C module '_FoundationCShims'
C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\share\ucrt.modulemap:15:12: error: module 'ucrt.C.complex' is incompatible with feature 'cplusplus'
13 | module ucrt [system] {
14 | module C {
15 | module complex {
| `- error: module 'ucrt.C.complex' is incompatible with feature 'cplusplus'
16 | /* disallow the header in C++ mode as it forwards to `ccomplex`. */
17 | requires !cplusplus
C:\Users\dima\AppData\Local\Programs\Swift\Platforms\6.0.1\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\_FoundationCShims/_CStdlib.h:122:10: note: submodule of top-level module 'ucrt' implicitly imported here
120 |
121 | #if __has_include(<complex.h>)
122 | #include <complex.h>
| `- note: submodule of top-level module 'ucrt' implicitly imported here
123 | #endif
124 |