MSVC compiler gets detected but ld.exe is used for linking test program
In command dev prompt for visual studio, the compiler gets detected correctly. But for some reason it will try to use ld.exe, which while I have it in my path, is obviously not what I am using for this use case. I am using cmake 3.16 and generate ninja code. It seems like this is a cmake issue however as the cmake cache contained the wrong compiler info.
-- The C compiler identification is MSVC 19.20.27508.1
-- The CXX compiler identification is MSVC 19.20.27508.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx86/x86/cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.20.27508/bin/Hostx86/x86/cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/b/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~1/NINJA-~1/ninja.exe cmTC_08cfa && [1/2] Building C object CMakeFiles\cmTC_08cfa.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_08cfa.exe
FAILED: cmTC_08cfa.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_08cfa.dir --rc=C:\PROGRA~2\WINDOW~4\10\bin\100171~1.0\x86\rc.exe --mt=C:\PROGRA~2\WINDOW~4\10\bin\100171~1.0\x86\mt.exe --manifests -- C:\Apps\cygwin64\cygwin64\bin\ld.exe /nologo CMakeFiles\cmTC_08cfa.dir\testCCompiler.c.obj /out:cmTC_08cfa.exe /implib:cmTC_08cfa.lib /pdb:cmTC_08cfa.pdb /version:0.0 /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:\Apps\cygwin64\cygwin64\bin\ld.exe /nologo CMakeFiles\cmTC_08cfa.dir\testCCompiler.c.obj /out:cmTC_08cfa.exe /implib:cmTC_08cfa.lib /pdb:cmTC_08cfa.pdb /version:0.0 /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_08cfa.dir/intermediate.manifest CMakeFiles\cmTC_08cfa.dir/manifest.res" failed (exit code 1) with the following output: