[CMake + MinGW + Windows 10上的Clang

问题描述 投票:5回答:1

我想使用Clang 4.0,CMake 3.8.1,MinGW x86_64 6.3.0编译应用程序。我已经尝试过:

cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++ ..\code

但是由于传递Visual Studio的编译器参数,所以测试程序的编译失败。我根本不想使用Visual Studio。输出:

-- The C compiler identification is Clang 4.0.0
-- The CXX compiler identification is Clang 4.0.0
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files/LLVM/bin/clang.exe" is not able to compile a simple test program.
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/DWIN32'
clang.exe: error: no such file or directory: '/D_WINDOWS'

我也尝试过:

cmake -G "MinGW Makefiles"  -DCMAKE_C_COMPILER="C:/Program Files/LLVM/msbuild-bin/cl.exe" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/msbuild-bin/cl.exe" -DCMAKE_LINKER="C:/Program Files/LLVM/bin/lld-link.exe" ..\code

并且在编译测试程序时也失败:

 C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo
 @CMakeFiles\cmTC_afe59.dir\objects1.rsp /out:cmTC_afe59.exe
 /implib:cmTC_afe59.lib
 /pdb:C:\...........\_build\CMakeFiles\CMakeTmp\cmTC_afe59.pdb
 /version:0.0 /machine:x64 /debug /pdbtype:sept /INCREMENTAL:YES
 /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib
 comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
 odbc32.lib odbccp32.lib

 error: could not open /pdbtype:sept: no such file or directory

是否可以在Windows 10上使用MinGw强制使用Clang?

c++ windows cmake clang mingw
1个回答
0
投票

这些是MSVC参数。我遇到了几个库,它们在检查IF(WIN32)中的CMakeLists.txt时都假定这些工作有效,而应该为IF(MSVC)

[G0和CCC处都有MinGW-w64,在http://winlibs.com/处可用,但由于不是MSVC,仍需要避免使用这些参数,因此我建议您修复CMakeLists.txt并再次运行cmake。

© www.soinside.com 2019 - 2024. All rights reserved.