# how to properly use clang on windows

**URL:** https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554
**Category:** Usage
**Created:** [December 4, 2023, 4:02pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554 "2023-12-04T16:02:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 4, 2023, 4:02pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/1 "2023-12-04T16:02:11Z")

</div>

I installed LLVM on windows (through the official installer) and I generate my project with the mingw-makefile generator (as I installed gcc through mingw).  
  
This fails with folllowing error during the compiler test stage (on the `project` command):

> lld-link: error: undefined symbol: \_\_guard\_eh\_cont\_table

What is the proper way to use clang through CMake on windows?

Thanks  
A.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 6, 2023, 12:53pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/2 "2023-12-06T12:53:12Z")

</div>

I believe you need a MinGW-aware LLVM build if you’re using the MinGW-provided CMake. I’m not sure what the official installer uses as a runtime.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 6, 2023, 8:00pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/3 "2023-12-06T20:00:41Z")

</div>

Only `make` is provided by MinGW. My `CMake` is a stand-alone installation.

Still, `make` may not be the right way to go on windows.

May be a specific toolset option is required?

A.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 6, 2023, 8:29pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/4 "2023-12-06T20:29:47Z")

</div>

Base on a strange ChatGPT answer, I added `set(CMAKE_SYSTEM_NAME Linux)` just before the `project` command.  
  
Doing I can generate a makefile but when I launch the build (with `make` from MinGW), on `iostream` inclusion in my code, I’ve got the following error:

> In file included from C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\iostream:9:  
> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include\yvals\_core.h:784:1: error: static\_assert failed  
> “Error in C++ Standard Library usage.”  
> \_EMIT\_STL\_ERROR(STL1000, “Unexpected compiler version, expected Clang 14.0.0 or newer.”);

I, indeed, have an older clang (12) and windows smartscreen is blocking installation of more recent versions.

Yet I don’t understand why I’m including a standard library from visual studio build tools.  
  
Especially when I’d like to compile with `-stdlib=libc++` option, but `clang` issues:

> warning: argument unused during compilation: ‘-stdlib=libc++’

Does this ring a bell?  
A.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 7, 2023, 10:55am UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/5 "2023-12-07T10:55:01Z")

</div>

Maybe it would be easier to use clang-cl (the clang version shipped with visual studio tools).  
But I’m unsure on the way to configure CMake to do so.

I have this link: [visual studio - How to use Clang-CL LLVM with VS2019 CMAKE? - Stack Overflow](https://stackoverflow.com/questions/64189111/how-to-use-clang-cl-llvm-with-vs2019-cmake).

I’m botherd by

> -DCMAKE\_CXX\_COMPILER=“C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe”

Why couldn’t I just do `-DCMAKE_CXX_COMPILER="clang-cl"` or simply `-DCMAKE_CXX_COMPILER="clang"` and make CMake find the right clang executable?  
  
(actual path to clang-cl may change from an install to another)

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [December 7, 2023, 8:13pm UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/6 "2023-12-07T20:13:52Z")

</div>

I use Clang from MSYS2 in Windows Terminal etc. without any issues, if you don’t mind installing/using Clang that way.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [December 8, 2023, 8:02am UTC](https://discourse.cmake.org/t/how-to-properly-use-clang-on-windows/9554/7 "2023-12-08T08:02:39Z")

</div>

Thx,

What CMake parameters do you use (generator, toolset,…)?

A.
