Sep 9, 2021.Knowledge
During the course of development, you may need to use some third-party or Windows functionality in order to fulfill the needs of your project. However, when including these header files, you may run into some strange compilation errors.
Some errors will mention Windows header files by name. This is the result of how Unreal redefines various macros from the Windows headers in order to avoid having to include Windows.h throughout the Unreal Engine codebase. As a result, if you want to include Windows.h or other Windows header files, you’ll need to remove these macro redefinitions first. The way we recommend is to surround your Windows includes with the following:
// Windows header includes
If you search through the Unreal Engine codebase for the above include statement, or “AllowWindowsPlatformTypes.h”, you’ll find many examples where this approach is used to surround Windows includes. Note: It is preferable to include Windows/MinWindows.h instead of Windows.h wherever possible.
You may also notice an error that looks similar to the following:
‘MACRO_NAME’ is not defined as a preprocessor macro, replacing with ‘0’ for ‘#if/#elif’
This is a warning that gets upgraded to an error in Unreal Engine’s build system, but many third-party libraries are not compatible with it.
You can disable this warning when including third-party code using the following set of macros:
// Third-party includes
There are examples of this throughout the codebase if you’d like an example for reference.
When a third-party library you plan to use also includes Windows headers, then you’ll need to combine both strategies as follows:
// Windows + third-party includes
If you’re having difficulty locating the specific include statements in your project that are causing issues, try setting bShowIncludes to true in your BuildConfiguration.xml file ( Build Configuration | Unreal Engine Documentation ). This will generate additional context that can help find the right location where the issues are happening.