在Windows 10上使用CMake + MinGW + Clang

6

我想使用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?

3
我不知道你是谁,或者你看到了什么,但我有这个“完全相同”的问题,连目录名称都一样...... 如果我们中的任何一个找到解决方案,请告诉另一个。 - 7H3_H4CK3R
我在Windows 10机器上使用CMake 3.12.1和NMake JOM生成器时,发现“objects1.rsp”行前面有一个at符号(@),导致出现相同的错误。 - jairo
1
我遇到了 lld-link.exe: error: could not open kernel32.lib: no such file or directory 的问题,因为 CMake 或其他工具将 kernel32.lib 等放在链接行上。我尝试使用 LLVM/clang 7.0 解决此问题。 - Dženan
1个回答

0

这些是MSVC参数。我遇到过几个库,在检查CMakeLists.txt中的IF(WIN32)时假定这些参数有效,而实际上应该是IF(MSVC)

有一个MinGW-w64可用,其中包含GCC和LLVM/CLang,网址为http://winlibs.com/,但由于它不是MSVC,仍然需要避免使用这些参数,因此建议您修复CMakeLists.txt并重新运行cmake。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接