如何在 Windows 上使用 MINGW 构建 clang?

Posted

技术标签:

【中文标题】如何在 Windows 上使用 MINGW 构建 clang?【英文标题】:How to build clang with MINGW on winodws? 【发布时间】:2019-10-09 11:29:29 【问题描述】:

我正在尝试在 Windows 8 上使用 MINGW 从源代码构建 clang。

我从llvm的官方页面下载了源代码和其他必要的工具

clang-llvm 源代码:git clone https://github.com/llvm/llvm-project.git

cmake and ninja我在下面的页面下载了

http://clang.llvm.org/docs/LibASTMatchersTutorial.html

我在终端上运行并给出以下命令

cmake -GNinja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt" -DCMAKE_BUILD_TYPE=Release /path/to/llvm 

所以cmake会在它运行的文件夹中输出一些文件

但是下一步如果我给忍者

5 步后出现以下错误

In file included from ../lib/Demangle/ItaniumDemangle.cpp:14:0:
../include/llvm/Demangle/ItaniumDemangle.h: In instantiation of 'void llvm::itanium_demangle::FloatLiteralImpl<Float>::printLeft(llvm::itanium_demangle::OutputStream&) const [with Float = long double]':
../lib/Demangle/ItaniumDemangle.cpp:587:1:   required from here
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: unknown conversion type character 'L' in format [-Wformat=]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
                       ^
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: too many arguments for format [-Wformat-extra-args]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/llvm/Demangle/ItaniumDemangle.h: In instantiation of 'void llvm::itanium_demangle::FloatLiteralImpl<Float>::printLeft(llvm::itanium_demangle::OutputStream&) const [with Float = double]':
../lib/Demangle/ItaniumDemangle.cpp:587:1:   required from here
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: unknown conversion type character 'a' in format [-Wformat=]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
                       ^
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: too many arguments for format [-Wformat-extra-args]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/llvm/Demangle/ItaniumDemangle.h: In instantiation of 'void llvm::itanium_demangle::FloatLiteralImpl<Float>::printLeft(llvm::itanium_demangle::OutputStream&) const [with Float = float]':
../lib/Demangle/ItaniumDemangle.cpp:587:1:   required from here
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: unknown conversion type character 'a' in format [-Wformat=]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
                       ^
../include/llvm/Demangle/ItaniumDemangle.h:2177:23: warning: too many arguments for format [-Wformat-extra-args]
       int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value);
               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[22/4328] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Chrono.cpp.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/Chrono.cpp.obj
C:\MinGW\bin\g++.exe  -DGTEST_HAS_RTTI=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I../lib/Support -Iinclude -I../include -std=c++11 -Werror=date-time -std=gnu++14 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment  -O2 -DNDEBUG    -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/Chrono.cpp.obj -MF lib\Support\CMakeFiles\LLVMSupport.dir\Chrono.cpp.obj.d -o lib/Support/CMakeFiles/LLVMSupport.dir/Chrono.cpp.obj -c ../lib/Support/Chrono.cpp
../lib/Support/Chrono.cpp: In function 'tm llvm::getStructTM(llvm::sys::TimePoint<>)':
../lib/Support/Chrono.cpp:35:15: error: '::localtime_s' has not been declared
   int Error = ::localtime_s(&Storage, &OurTime);
               ^~
[25/4328] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj
C:\MinGW\bin\g++.exe  -DGTEST_HAS_RTTI=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I../lib/Support -Iinclude -I../include -std=c++11 -Werror=date-time -std=gnu++14 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment  -O2 -DNDEBUG    -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 ../lib/Support/CodeGenCoverage.cpp
In file included from ../lib/Support/CodeGenCoverage.cpp:18:0:
../include/llvm/Support/Mutex.h:29:12: error: 'recursive_mutex' in namespace 'std' does not name a type
       std::recursive_mutex impl;
            ^~~~~~~~~~~~~~~
../include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::lock()':
../include/llvm/Support/Mutex.h:35:11: error: 'impl' was not declared in this scope
           impl.lock();
           ^~~~
../include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::unlock()':
../include/llvm/Support/Mutex.h:48:11: error: 'impl' was not declared in this scope
           impl.unlock();
           ^~~~
../include/llvm/Support/Mutex.h: In member function 'bool llvm::sys::SmartMutex<mt_only>::try_lock()':
../include/llvm/Support/Mutex.h:62:18: error: 'impl' was not declared in this scope
           return impl.try_lock();
                  ^~~~
[26/4328] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CachePruning.cpp.obj
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/CachePruning.cpp.obj
C:\MinGW\bin\g++.exe  -DGTEST_HAS_RTTI=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I../lib/Support -Iinclude -I../include -std=c++11 -Werror=date-time -std=gnu++14 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment  -O2 -DNDEBUG    -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/CachePruning.cpp.obj -MF lib\Support\CMakeFiles\LLVMSupport.dir\CachePruning.cpp.obj.d -o lib/Support/CMakeFiles/LLVMSupport.dir/CachePruning.cpp.obj -c ../lib/Support/CachePruning.cpp
In file included from ../lib/Support/CachePruning.cpp:16:0:
../include/llvm/Support/Errc.h:65:23: error: 'not_supported' is not a member of 'std::errc'
   not_supported = int(std::errc::not_supported),
                       ^~~
[27/4328] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/APFloat.cpp.obj
ninja: build stopped: subcommand failed.

为什么clang依赖于Windows。? 在Windows上构建clang时我做错了什么?

如果有解决办法请告诉我。

【问题讨论】:

【参考方案1】:

我有同样的问题。我只是用chocolatey安装clang。https://chocolatey.org/ 安装后,以管理员身份打开 windows power shell,然后输入以下命令:choco install llvm. 这应该会安装编译器。

【讨论】:

以上是关于如何在 Windows 上使用 MINGW 构建 clang?的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 MinGW 在 Linux 上构建 Crypto++ 库?

如何在 mingw64 上使用 boost.test 构建测试?

如何在 Windows 中使用 MinGW 构建 OpenSSL? [关闭]

`DllMainCRTStartup@12' 的多重定义,同时使用 mingw32 在 Windows 上构建 glew

如何使用 mingw 在 Windows 中构建 protobuf-c?

如何使用MinGW在Windows中构建Google的protobuf