# Enable preprocessor flags during build

**URL:** <https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892>\
**Category:** C++ interoperability\
**Tags:** cxx-interop\
**Created:** [June 29, 2023, 12:02pm UTC](https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892 "2023-06-29T12:02:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marius/32/14698_2.png) [@marius](https://forums.swift.org/u/marius)\
**Post date:** [June 29, 2023, 12:02pm UTC](https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892/1 "2023-06-29T12:02:45Z")

</div>

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:

```c++
#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!

---

<div class="post-metadata">

**Author:** ![egor.zhdan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/egor.zhdan/32/44150_2.png) [@egor.zhdan](https://forums.swift.org/u/egor.zhdan)\
**Post date:** [June 29, 2023, 12:04pm UTC](https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892/2 "2023-06-29T12:04:48Z")

</div>

Could you try passing `-Xcc -D -Xcc UNIX_ENABLED` to swiftc to make sure it forwards the `-D` to clang?

---

<div class="post-metadata">

**Author:** ![marius](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marius/32/14698_2.png) [@marius](https://forums.swift.org/u/marius)\
**Post date:** [June 29, 2023, 1:28pm UTC](https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892/3 "2023-06-29T13:28:56Z")

</div>

Ohh that did the trick! Thank you very much!

---

<div class="post-metadata">

**Author:** ![marius](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/marius/32/14698_2.png) [@marius](https://forums.swift.org/u/marius)\
**Post date:** [June 29, 2023, 3:48pm UTC](https://forums.swift.org/t/enable-preprocessor-flags-during-build/65892/4 "2023-06-29T15:48:51Z")

</div>

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?
