build errors with MinGW-W64 GCC-8.1.0 on Windows

Dear LLVM/clang people,

I’m new to LLVM. I used TDM-GCC toolchain with gcc version 5.1.0 before but
I want to move on getting LLVM and Clang to work on my system: Windows 7

I would like to go for a MinGW64 toolchain to build the newest version of
LLVM and clang.

I downloaded MinGW-W64 GCC-8.1.0 from here:

There I selected the x86_64-posix-seh version believing that would be the
best one. I got llvm and clang plus the llvm libc++ standard library as
suggested on the getting started webpage.

I put the mingw-w64 bin folder in my PATH.
gcc -dumpversion
shown 8.1.0

In the llvm build folder I did:
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..
that completed succesfully

mingw32-make -f Makefile

It builds to 57%, then a bunch of errors:
C:\dev\llvm\projects\libcxx\src\support\win32\thread_win32.cpp:156:8: error:
'InitOnceExecuteOnce' was not declared in this scope
C:\dev\llvm\projects\libcxx\src\support\win32\thread_win32.cpp:163:6: error:
redefinition of 'bool
3) And a couple of more errors all in thread_win32.cpp.

So I think it would have been better to select the Mingw-w64
x86_64-win32-seh or even x86_64-win32-sjlj version instead?

Is a recent Mingw-w64 toolchain version like 8.1.0 a good one to build
llvm/clang? Or would an older one be more stable?

Thanks anyway for any suggestions.
Best regards,
Maarten Verhage

Hi Maarten,

I am not a windows user and never build with mingw in my life. :slight_smile:

Did you try out building a release-version of LLVM first? Sometimes
there are breaking changes committed that e.g. linux-users will not
notice on their system. Our Buildbots have to catch up first before the
issue is then fixed (

I myself did build LLVM with gcc-8 when it got released, which worked.
But I didnt retry since then.

Best, Jonas

Hello, Maarten.

I have partially built LLVM with MinGW-w64 8.1.0 (some llvm shared libs needed, not clang and stdlib).

For experimenting with build I personally recommend using ninja instead of mingw32-make because it allows resuming without rebuilding everything from scratch if I added a linker flag into a CMake cache variable.

So I think it would have been better to select the Mingw-w64 x86_64-win32-seh or even x86_64-win32-sjlj version instead?

I guess, no. If something somewhere uses std::thread and other threading stuff, you will have problems since "win32" versions of the toolchain lack it since it is implemented upon pthreads.

'InitOnceExecuteOnce' was not declared in this scope

some header is needed and it exists in MinGW since I get another error that the symbol is not found on linking stage (so yo may have problem with it anyway).

According your config, cmake -G “MinGW Makefiles” -DCMAKE_BUILD_TYPE=Release …, it occur an error, am I missing something ?

admin@DESKTOP-60K0V6B MINGW64 /e/source/llvm-project (main)
$ cd build

admin@DESKTOP-60K0V6B MINGW64 /e/source/llvm-project/build (main)
$ cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..
CMake Warning:
  Ignoring extra path from command line:


CMake Error: The source directory "E:/source/llvm-project" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.