How to use Clang on Windows ?

I am on the same boat, but I am using binary build instead of source code.

I have successfully made Clang work on Windows, using Clang as the compiler and MSVC as the toolchain. I did not try to use MinGW GCC toolchain because Epic Games did not build against it on Windows, I don’t know if it is recommended.

This is my BuildConfiguration.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
    <WindowsPlatform>
        <Compiler>Clang</Compiler>
        <CompilerVersion>Latest</CompilerVersion>
        <Toolchain>VisualStudio2022</Toolchain>
        <ToolchainVersion>14.34.31933</ToolchainVersion>
    </WindowsPlatform>
    <ProjectFileGenerator>
        <Format>VisualStudioCode</Format>
    </ProjectFileGenerator>
</Configuration>

The last part <ProjectFileGenerator> is not necessary, it just makes UnrealBuildTool run -Mode=VSCode when you click “Generate Visual Studio project files” from the context menu on your .uproject in Explorer.

There are 3 XML files in 3 different directories (each serve a purpose) to choose from to setup Clang as the compiler in BuildConfiguration.xml:

  • %appdata%\Unreal Engine\UnrealBuildTool\
  • YourProjectDirectory\Saved\UnrealBuildTool\
  • %username%\Documents\Unreal Engine\Saved\UnrealBuildTool\ (This one is unique to source builds, it does not exist for binary UE – also not sure if the directory is correct)

Documentation: Use Clang to Build Microsoft Platforms in Unreal Engine | Unreal Engine 5.4 Documentation | Epic Developer Community

After that, you need to run -Mode=GenerateClangDatabase in CMD using UnrealBuildTool.exe to make clangd work.
Directory: C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\DotNET\UnrealBuildTool

clangd: https://clangd.llvm.org/
clangd installation: Getting started

A thread on UE forums of many users trying to make clangd work: Get compile_commands.json

@dzemzmcdonalda found out that -Mode=GenerateClangDatabase is not incremental: UBT GenerateClangDatabase is NOT incremental and recreates whole compile_commands.json each time

Assuming you want to use VS Code with clangd: https://www.youtube.com/watch?v=JxfNn5DYG_o

At this point, it just takes too much time to setup and maintain. I just reverted back to MSVC. I wish I can continue down with LLVM road, but it is not intuitive.

Let me know what happens, I am still interested in it.

If only Epic Games can make a complete guide on how to correctly setup and use Clang on all platforms, since I believe they use Clang themselves. And if it is possible to use Clang on Windows without MSVC toolchain.