how to properly use clang on windows

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.

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.

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.

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.

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.

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)

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

Thx,

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

A.