marius
(Marius)
1
Hey folks C/C++ interop question:
I have a C++ header file that only exposes a class if a preprocessor flag (I think that’s how you call it?) is set:
#ifdef UNIX_ENABLED
class Some_Class {
...
}
#endif // UNIX_ENABLED
When I call the swift compiler:
swiftc MyApp.swift -cxx-interoperability-mode=default -Xcc -std=c++17 -I cxx -c -parse-as-library
and try to use Some_Class in MyApp.swift it obviously can’t find that class. I tried using -D UNIX_ENABLED but that didn’t help
Any ideas how I could get this compiling?
Note: When I don’t use Some_Class in MyApp.swift the project builds perfectly fine
This is part of a bigger project which uses SCons (
). In pure C++ areas of the project other developers used the following SCons code to enable it:
env.Append(CPPDEFINES=["UNIX_ENABLED"])
Many thanks in advance!
Could you try passing -Xcc -D -Xcc UNIX_ENABLED to swiftc to make sure it forwards the -D to clang?
1 Like
marius
(Marius)
3
Ohh that did the trick! Thank you very much!
marius
(Marius)
4
Small follow-up: Is it possible to view the "generated" Swift code? It would really help me seeing how Swift interprets the C++ code. In Xcode you can cmd-click the imported module to view the Swift representation of the C++ code - is this possible outside of Xcode?
1 Like