Can't for the life of me get LLVM 13 to build on Windows

I’ve been struggling for a couple weeks now to try to get LLVM 13 to build on Windows, but I just cannot seem to get it to work. I’ve tried a bunch of times changing out various things including trying different compilers, specifically clang 13 itself using the binaries from the LLVM website as well as various different MinGW compilers. Here’s a summary of my latest attempt:

package command version
LLVM repository git tag 13.0.0
CMake cmake-gui 3.21.4
ninja ninja -C build 1.10.2
gcc/g++ mingw-w64 x86_64-8.1.0-win32-sjlj-rt_v6-rev0 from the Mingw-builds sourceforge
Windows Windows 10 64 bit version 2004
CMake option value
CMAKE_BUILD_TYPE Release
LLVM_ENABLE_PROJECTS clang;clang-tools-extra;lld;lldb
LLVM_ENABLE_RUNTIMES libcxx;libcxxabi
CMAKE_C_COMPILER C:\Program Files\mingw-w64\x86_64-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\gcc.exe
CMAKE_CXX_COMPILER C:\Program Files\mingw-w64\x86_64-8.1.0-win32-sjlj-rt_v6-rev0\mingw64\bin\g++.exe
CMAKE_MAKE_PROGRAM C:/PROGRA~1/NINJA-~1/ninja.exe

However when I try to build I get error: 'mutex' is not a member of 'std' along with note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'? on a bunch of different files.

Since new users can’t upload files here I’ve used pastebin to post my CMake output and my CMakeCache, both from that latest attempt.

And since I can only link two files, here’s my ninja output:

Z:\Projects\llvm-project>ninja -C build
ninja: warning: bad deps log signature or version; starting over
ninja: Entering directory `build'
[28/5864] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj
C:\PROGRA~1\MINGW-~1\X86_64~1.0-W\mingw64\bin\G__~1.EXE -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IZ:/Projects/llvm-project/build/lib/Support -IZ:/Projects/llvm-project/llvm/lib/Support -IZ:/Projects/llvm-project/build/include -IZ:/Projects/llvm-project/llvm/include -Wa,-mbig-obj -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wmisleading-indentation -ffunction-sections -fdata-sections  -O2 -DNDEBUG -UNDEBUG -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj -MF lib\Support\CMakeFiles\LLVMSupport.dir\CodeGenCoverage.cpp.obj.d -o lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj -c Z:/Projects/llvm-project/llvm/lib/Support/CodeGenCoverage.cpp
In file included from Z:/Projects/llvm-project/llvm/lib/Support/CodeGenCoverage.cpp:17:
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:29:12: error: 'recursive_mutex' in namespace 'std' does not name a type
       std::recursive_mutex impl;
            ^~~~~~~~~~~~~~~
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:29:7: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:19:1:
+#include <mutex>

Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:29:7:
       std::recursive_mutex impl;
       ^~~
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::lock()':
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:35:11: error: 'impl' was not declared in this scope
           impl.lock();
           ^~~~
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:35:11: note: suggested alternative: 'fmal'
           impl.lock();
           ^~~~
           fmal
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::unlock()':
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:48:11: error: 'impl' was not declared in this scope
           impl.unlock();
           ^~~~
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:48:11: note: suggested alternative: 'fmal'
           impl.unlock();
           ^~~~
           fmal
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::try_lock()':
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:62:18: error: 'impl' was not declared in this scope
           return impl.try_lock();
                  ^~~~
Z:/Projects/llvm-project/llvm/include/llvm/Support/Mutex.h:62:18: note: suggested alternative: 'fmal'
           return impl.try_lock();
                  ^~~~
                  fmal
[40/5864] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.obj
C:\PROGRA~1\MINGW-~1\X86_64~1.0-W\mingw64\bin\G__~1.EXE -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IZ:/Projects/llvm-project/build/lib/Support -IZ:/Projects/llvm-project/llvm/lib/Support -IZ:/Projects/llvm-project/build/include -IZ:/Projects/llvm-project/llvm/include -Wa,-mbig-obj -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wmisleading-indentation -ffunction-sections -fdata-sections  -O2 -DNDEBUG -UNDEBUG -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.obj -MF lib\Support\CMakeFiles\LLVMSupport.dir\CrashRecoveryContext.cpp.obj.d -o lib/Support/CMakeFiles/LLVMSupport.dir/CrashRecoveryContext.cpp.obj -c Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp
In file included from Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:16:
Z:/Projects/llvm-project/llvm/include/llvm/Support/thread.h: In static member function 'static unsigned int llvm::thread::hardware_concurrency()':
Z:/Projects/llvm-project/llvm/include/llvm/Support/thread.h:109:17: error: 'std::thread' has not been declared
     return std::thread::hardware_concurrency();
                 ^~~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp: At global scope:
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:27: error: 'mutex' is not a member of 'std'
 static ManagedStatic<std::mutex> gCrashRecoveryContextMutex;
                           ^~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:19:1:
+#include <mutex>

Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:27:
 static ManagedStatic<std::mutex> gCrashRecoveryContextMutex;
                           ^~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:27: error: 'mutex' is not a member of 'std'
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:27: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:32: error: template argument 1 is invalid
 static ManagedStatic<std::mutex> gCrashRecoveryContextMutex;
                                ^
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:32: error: template argument 2 is invalid
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:88:32: error: template argument 3 is invalid
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp: In static member function 'static void llvm::CrashRecoveryContext::Enable()':
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:24: error: 'mutex' is not a member of 'std'
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                        ^~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:24: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:24: error: 'mutex' is not a member of 'std'
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:24: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:29: error: template argument 1 is invalid
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                             ^
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:34: error: invalid type argument of unary '*' (have 'int')
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:140:31: warning: unused variable 'L' [-Wunused-variable]
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                               ^
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp: In static member function 'static void llvm::CrashRecoveryContext::Disable()':
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:24: error: 'mutex' is not a member of 'std'
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                        ^~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:24: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:24: error: 'mutex' is not a member of 'std'
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:24: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:29: error: template argument 1 is invalid
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                             ^
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:34: error: invalid type argument of unary '*' (have 'int')
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
Z:/Projects/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:149:31: warning: unused variable 'L' [-Wunused-variable]
   std::lock_guard<std::mutex> L(*gCrashRecoveryContextMutex);
                               ^
[41/5864] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CommandLine.cpp.obj
ninja: build stopped: subcommand failed.

Any help getting a working LLVM with libc++ and a clang that supports libc++ and modules would be much appreciated. Thoughts?

Your issue is that you chose a toolchain that does not support C++11 multithreading. Therefore things like mutex are simply not defined.

One way to fix this would be to set the cmake option LLVM_ENABLE_THREADS to false.

Another would be for you to not download a win32-sljl version of MINGW, but the posix-seh. It has C++11 threading and also faster exceptions and is generally preferred.

Last but not least, if you only want a working clang toolchain with libc++ and all the other llvm tooling and don’t care about building it yourself you can checkout this repo, it has precompiled binaries you can download: GitHub - mstorsjo/llvm-mingw: An LLVM/Clang/LLD based mingw-w64 toolchain

1 Like

Thanks for the suggestion to use llvm-mingw :+1:t2:. The reason I started any of this was because I want to try playing around with modules in C++, and that would meet that criteria. Now that I’ve put so much time trying to get LLVM to build I think I’d still like to try to see that through, llvm-mingw could be useful until I get that working. Alas when I tried it I still got errors on this simple hello world program:

#include <iostream>;

int main(int argc, char **argv)
{
    std::cout << "Hello World" << std::endl;
    return 0;
}

In particular it seems to be complaining about building std, which I wouldn’t think it should need to do. I’ve put the full build output from my IDE on pastebin.

After changing basically just the compiler from x86_64-8.1.0-win32-sjlj-rt_v6-rev0 to x86_64-8.1.0-posix-seh-rt_v6-rev0 (technically I also update windows 10 to version 21H1, but I doubt that makes a difference) I’m now getting some new build errors when I run ninja, such as: error: 'WSAPoll' was not declared in this scope, error: aggregate 'pollfd pfd' has incomplete type and cannot be defined, and error: 'POLLIN' was not declared in this scope

This time I’ve used pastebin for my ninja output and my CMakeCache, and pasted my CMake output below.

clang project is enabled
clang-tools-extra project is enabled
compiler-rt project is disabled
cross-project-tests project is disabled
libc project is disabled
libclc project is disabled
libcxx project is disabled
libcxxabi project is disabled
libunwind project is disabled
lld project is enabled
lldb project is enabled
mlir project is disabled
openmp project is disabled
parallel-libs project is disabled
polly project is disabled
pstl project is disabled
flang project is disabled
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) 
Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) 
Could NOT find Backtrace (missing: Backtrace_LIBRARY Backtrace_INCLUDE_DIR) 
Native target architecture is X86
Threads enabled.
Doxygen disabled.
Go bindings disabled.
Ninja version: 1.10.2
Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH) 
OCaml bindings disabled.
LLVM host triple: x86_64-w64-windows-gnu
LLVM default target triple: x86_64-w64-windows-gnu
LLVMHello ignored -- Loadable modules not supported on this platform.
Targeting AArch64
Targeting AMDGPU
Targeting ARM
Targeting AVR
Targeting BPF
Targeting Hexagon
Targeting Lanai
Targeting Mips
Targeting MSP430
Targeting NVPTX
Targeting PowerPC
Targeting RISCV
Targeting Sparc
Targeting SystemZ
Targeting WebAssembly
Targeting X86
Targeting XCore
Clang version: 13.0.0
Not building amdgpu-arch: hsa-runtime64 not found
PrintFunctionNames ignored -- Loadable modules not supported on this platform.
AnnotateFunctions ignored -- Loadable modules not supported on this platform.
Attribute ignored -- Loadable modules not supported on this platform.
CallSuperAttr ignored -- Loadable modules not supported on this platform.
LLD version: 13.0.0
Could NOT find LibEdit (missing: LibEdit_INCLUDE_DIRS LibEdit_LIBRARIES) 
Enable editline support in LLDB: FALSE
Could NOT find CursesAndPanel (missing: CURSES_INCLUDE_DIRS CURSES_LIBRARIES PANEL_LIBRARIES) 
Enable curses support in LLDB: FALSE
Could NOT find LibLZMA (missing: LIBLZMA_LIBRARY LIBLZMA_INCLUDE_DIR LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET) 
Enable LZMA compression support in LLDB: FALSE
Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) (Required is at least version "3.0")
SWIG 3 or later is required for Lua support in LLDB but could not be found
Could NOT find LuaAndSwig (missing: LUA_LIBRARIES LUA_INCLUDE_DIR SWIG_EXECUTABLE) 
Enable Lua scripting support in LLDB: FALSE
Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) (Required is at least version "3.0")
SWIG 3 or later is required for Python support in LLDB but could not be found
Could NOT find PythonAndSwig (missing: Python3_LIBRARIES Python3_INCLUDE_DIRS SWIG_EXECUTABLE) 
Enable Python scripting support in LLDB: FALSE
Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR) (Required is at least version "2.8")
Enable Libxml 2 support in LLDB: FALSE
LLDB version: 13.0.0
BugpointPasses ignored -- Loadable modules not supported on this platform.
CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.21/Modules/ExternalProject.cmake:2235 (message):
  Policy CMP0114 is not set: ExternalProject step targets fully adopt their
  steps.  Run "cmake --help-policy CMP0114" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  ExternalProject target 'runtimes' would depend on the targets for step(s)
  'clean' under policy CMP0114, but this is being left out for compatibility
  since the policy is not set.
Call Stack (most recent call first):
  cmake/modules/LLVMExternalProjectUtils.cmake:333 (ExternalProject_Add_StepTargets)
  runtimes/CMakeLists.txt:226 (llvm_ExternalProject_Add)
  runtimes/CMakeLists.txt:363 (runtime_default_target)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Version: 0.0.0
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- failed to compile
CMake Warning at utils/benchmark/CMakeLists.txt:248 (message):
  Using std::regex with exceptions disabled is not fully supported


-- Performing Test HAVE_STEADY_CLOCK -- success
Configuring done
Generating done

Thanks again for any help you can provide to get this working.