clang-cl: wrong linker when projects enable ASM before C
If my CMakeLists has the line project(my-project LANGUAGES C ASM)
and I configure it with cmake <source-dir> -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_ASM_COMPILER=clang-cl
, configuration works fine. If I instead declare my project with project(my-project LANGUAGES ASM C)
, configuration fails:
-- The ASM compiler identification is Clang
-- Found assembler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- The C compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/marc/tmp/my-project/b/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~2/MIB055~1/2019/ENTERP~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe cmTC_f9873 && [1/2] Building C object CMakeFiles\cmTC_f9873.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_f9873.exe
FAILED: cmTC_f9873.exe
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_f9873.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt="" --manifests -- C:\PROGRA~2\MIB055~1\2019\ENTERP~1\VC\Tools\Llvm\x64\bin\LDLLD~1.EXE /nologo CMakeFiles\cmTC_f9873.dir\testCCompiler.c.obj /out:cmTC_f9873.exe /implib:cmTC_f9873.lib /pdb:cmTC_f9873.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 && cd ."
LINK Pass 1: command "C:\PROGRA~2\MIB055~1\2019\ENTERP~1\VC\Tools\Llvm\x64\bin\LDLLD~1.EXE /nologo CMakeFiles\cmTC_f9873.dir\testCCompiler.c.obj /out:cmTC_f9873.exe /implib:cmTC_f9873.lib /pdb:cmTC_f9873.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 /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_f9873.dir/intermediate.manifest CMakeFiles\cmTC_f9873.dir/manifest.res" failed (exit code 1) with the following output:
ld.lld: error: cannot open /nologo: no such file or directory
ld.lld: error: CMakeFiles\cmTC_f9873.dir\testCCompiler.c.obj: unknown file type
ld.lld: error: cannot open /out:cmTC_f9873.exe: no such file or directory
ld.lld: error: cannot open /implib:cmTC_f9873.lib: no such file or directory
ld.lld: error: cannot open /pdb:cmTC_f9873.pdb: no such file or directory
ld.lld: error: cannot open /version:0.0: no such file or directory
ld.lld: error: cannot open /machine:x64: no such file or directory
ld.lld: error: cannot open /debug: no such file or directory
ld.lld: error: cannot open /INCREMENTAL: no such file or directory
ld.lld: error: cannot open /subsystem:console: no such file or directory
ld.lld: error: cannot open kernel32.lib: no such file or directory
ld.lld: error: cannot open user32.lib: no such file or directory
ld.lld: error: cannot open gdi32.lib: no such file or directory
ld.lld: error: cannot open winspool.lib: no such file or directory
ld.lld: error: cannot open shell32.lib: no such file or directory
ld.lld: error: cannot open ole32.lib: no such file or directory
ld.lld: error: cannot open oleaut32.lib: no such file or directory
ld.lld: error: cannot open uuid.lib: no such file or directory
ld.lld: error: cannot open comdlg32.lib: no such file or directory
ld.lld: error: cannot open advapi32.lib: no such file or directory
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
ninja: build stopped: subcommand failed.
For some reason cmake uses ld.lld
as the linker instead of lld-link
but still uses MSVC linker arguments, which ld.lld
does not understand.
Edited by Brad King