There are plenty of questions and answers relating to this, but none of them have gotten me past my current problem. I can build using CMake/Ninja/clang-cl fine from within Visual Studio, but I want this to be done within a Github Action so I need to be able to do it from the command line - but it fails the configuration stage.
Running from Powershell:
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat' x64 10.0.22000.0
cmake -G "Ninja" `
-DVCPKG_TARGET_TRIPLET:STRING="x64-windows-static" `
-DCMAKE_CXX_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe" `
-DCMAKE_C_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe" `
-DCMAKE_RC_COMPILER:FILEPATH="C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/llvm-rc.exe" `
-DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" `
..\arg_router\
Yields:
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.0
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
... VCPKG stuff ...
-- Running vcpkg install - done
-- The CXX compiler identification is Clang 13.0.0 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/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/camde/Documents/workspace/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_81aba && [1/2] Building CXX object CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_81aba.exe
FAILED: cmTC_81aba.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_81aba.dir --rc=C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\llvm-rc.exe --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj /out:cmTC_81aba.exe /implib:cmTC_81aba.lib /pdb:cmTC_81aba.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 && cmd.exe /C "cd /D C:\Users\camde\Documents\workspace\build\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/camde/Documents/workspace/arg_router/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp/cmTC_81aba.exe -installedDir C:/Users/camde/Documents/workspace/arg_router/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_81aba.dir\testCXXCompiler.cxx.obj /out:cmTC_81aba.exe /implib:cmTC_81aba.lib /pdb:cmTC_81aba.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_81aba.dir/intermediate.manifest CMakeFiles\cmTC_81aba.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: could not open 'kernel32.lib': no such file or directory
lld-link: error: could not open 'user32.lib': no such file or directory
lld-link: error: could not open 'gdi32.lib': no such file or directory
lld-link: error: could not open 'winspool.lib': no such file or directory
lld-link: error: could not open 'shell32.lib': no such file or directory
lld-link: error: could not open 'ole32.lib': no such file or directory
lld-link: error: could not open 'oleaut32.lib': no such file or directory
lld-link: error: could not open 'uuid.lib': no such file or directory
lld-link: error: could not open 'comdlg32.lib': no such file or directory
lld-link: error: could not open 'advapi32.lib': no such file or directory
lld-link: error: could not open 'msvcrtd.lib': no such file or directory
lld-link: error: could not open 'oldnames.lib': no such file or directory
ninja: build stopped: subcommand failed.
Those libraries are installed in C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64
which I would have thought vcvarsall.bat
would have setup some env var that points to them - but clearly it didn't. What's weirder is that when I configure CMake from within VS, it doesn't need to pass the CMAKE_RC_COMPILER
arg but if I don't then it fails stating that rc.exe
can't be found.
Clearly VS is doing some extra configuration in the background before CMake is configured - what is it!?
As an extra data point, if I try to run the above CMake configuration command within the 'Developer Powershell for VS 2022', it fails for a different reason:
-- Running vcpkg install - done
-- The CXX compiler identification is Clang 13.0.0 with MSVC-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe
-- Check for working CXX compiler: C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken
CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"C:/PROGRAM FILES/MICROSOFT VISUAL STUDIO/2022/COMMUNITY/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/camde/Documents/workspace/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe cmTC_3b037 && [1/2] Building CXX object CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_3b037.exe
FAILED: cmTC_3b037.exe
cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_3b037.dir --rc=C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\llvm-rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x86\mt.exe --manifests -- C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj /out:cmTC_3b037.exe /implib:cmTC_3b037.lib /pdb:cmTC_3b037.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 && cmd.exe /C "cd /D C:\Users\camde\Documents\workspace\build\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/camde/Documents/workspace/arg_router/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/camde/Documents/workspace/build/CMakeFiles/CMakeTmp/cmTC_3b037.exe -installedDir C:/Users/camde/Documents/workspace/arg_router/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
LINK Pass 1: command "C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\lld-link.exe /nologo CMakeFiles\cmTC_3b037.dir\testCXXCompiler.cxx.obj /out:cmTC_3b037.exe /implib:cmTC_3b037.lib /pdb:cmTC_3b037.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_3b037.dir/intermediate.manifest CMakeFiles\cmTC_3b037.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: <root>: undefined symbol: mainCRTStartup
ninja: build stopped: subcommand failed.