CLion Windows 中的 clang++,如何使用 MinGW--w64 运行 而不是 Windows VC?

clang++ in CLion Windows, how to run with MinGW--w64 instead of Windows VC?

我有什么

我想要的

使用 clang++ 编译器设置功能性 CMake 配置文件。

我已经按照上面的link设置了一个CMake配置文件。但是,clion 给出错误

The Clang compiler tool
"C:/Program Files/LLVM/bin/clang.exe"

targets the MSVC ABI but has a GNU-like command-line interface.  This is
not supported.  Use 'clang-cl' instead, e.g.  by setting 'CC=clang-cl' in
the environment.  Furthermore, use the MSVC command-line environment.

如果我将 C 和 CXX 编译器设置为 clang-cl 而不是将 TOOLCHAIN PREFIX 设置为 LLVM,则会出现错误。

CMake Error at C:/Program Files/JetBrains/CLion 
2018.1/bin/cmake/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 
(message):
The C compiler

"C:/Program Files/LLVM/bin/clang-cl.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/Users/huang/Documents/Programs/grade/cmake-build-release-
clang-1/CMakeFiles/CMakeTmp

Run Build Command:"C:/mingw64/bin/mingw32-make.exe" "cmTC_181bf/fast"
C:/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_181bf.dir\build.make 
CMakeFiles/cmTC_181bf.dir/build
mingw32-make.exe[1]: Entering directory 
'C:/Users/huang/Documents/Programs/grade/cmake-build-release-clang-
1/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_181bf.dir/testCCompiler.c.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe  /nologo   /DWIN32 /D_WINDOWS /W3  /MDd 
/Zi /Ob0 /Od /RTC1   /FoCMakeFiles\cmTC_181bf.dir\testCCompiler.c.obj 
/FdCMakeFiles\cmTC_181bf.dir/ -c 
C:\Users\huang\Documents\Programs\grade\cmake-build-release-clang-
1\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTC_181bf.exe
"C:\Program Files\JetBrains\CLion 2018.1\bin\cmake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_181bf.dir\link.txt --verbose=1
"C:\Program Files\JetBrains\CLion 2018.1\bin\cmake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_181bf.dir --manifests  -- CMAKE_LINKER-NOTFOUND /nologo @CMakeFiles\cmTC_181bf.dir\objects1.rsp  /out:cmTC_181bf.exe /implib:cmTC_181bf.lib /pdb:C:\Users\huang\Documents\Programs\grade\cmake-build-release-clang-1\CMakeFiles\CMakeTmp\cmTC_181bf.pdb /version:0.0  /machine:x64  /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib 
RC Pass 1: command "rc /foCMakeFiles\cmTC_181bf.dir/manifest.res CMakeFiles\cmTC_181bf.dir/manifest.rc" failed (exit code 0) with the following output:
缁崵绮洪幍鍙ョ瑝閸掔増瀵氱�规氨娈戦弬鍥︽閵嗕慷ingw32-make.exe[1]: *** [CMakeFiles\cmTC_181bf.dir\build.make:98: cmTC_181bf.exe] Error -1
mingw32-make.exe[1]: Leaving directory 'C:/Users/huang/Documents/Programs/grade/cmake-build-release-clang-1/CMakeFiles/CMakeTmp'
mingw32-make.exe: *** [Makefile:125: cmTC_181bf/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

我猜可能是因为我没有在命令行中设置目标,默认目标是VC。在CLion界面,我应该怎么做?

有 2 个问题的组合:

  1. CMake 不支持本机 clang++.exe 驱动程序(请参阅相关 ticket)。
  2. 即使可以,我也不认为 MinGW 可以使用已安装的 clang 发行版。您必须将 clang 安装为 MinGW 包(参见例如 this readme, here 是特定包)。

目前 CLion 本身没有对此用例的具体支持(因此当一切设置正确时它应该可以工作,但它没有提供任何帮助)。