Clang build on windows


To build clang on windows i have gone through the following step’s,
Try-1 on a windows machine

build.log (13.4 KB)

The problem is that CMake caches some build configuration options for you, against your will.

Remove your whole build directory and try the `cmake` invocation from your second try again, and it should work (It’s picking up the cached value of the `-A` argument from your first invocation, which isn’t valid for Makefiles).

Looking at your other options that you provide to the build system, if you want your default target triple to be x86-based, you should specify `-DLLVM_TARGETS_TO_BUILD=“X86;RISCV”` (RISC-V is no longer experimental, so it can go in either `LLVM_TARGETS_TO_BUILD` or `LLVM_EXPERIMENTAL_TARGETS_TO_BUILD` now).

Hope this helps!


The CMake line in your first attempt does not build the project it just generates build files. The command you shared:

cmake -DLLVM_ENABLE_PROJECTS=clang -G “Visual Studio 15 2017” -A x64 -Thost=x64 …/llvm

should set up your build directory (before building anything), to run the build try “cmake --build .” (MSVC build can be invoked from the command line, but the command is much more complicated).

For the second attempt, I haven’t had luck with Makefiles on Windows (but maybe it is just me), but Ninja with LLVM works really well. To configure the build with ninja use Ninja generator in CMake (-GNinja on command line). Note that ninja is parallel by default and you might need to limit the number of concurrent link jobs, so that you don’t run out of memory. The configuration that has worked the best for me is Ninja with LLVM toolchain (clang+lld). So in the Visual Studio shell with LLVM release on the PATH it would look something like this:


Parallel link parameter is best set by trial and error, but I was able to get away with four lobs of LLVM 8 on 16 GB of ram. To build with ninja simply invoke ‘ninja’.

Hope that helps, let me know if you have any questions.