2

有很多与此相关的问题和答案,但没有一个能让我摆脱当前的问题。我可以在 Visual Studio 中使用 CMake/Ninja/clang-cl 进行构建,但我希望在 Github 操作中完成,所以我需要能够从命令行执行它 - 但它在配置阶段失败。

从 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\

产量:

**********************************************************************
** 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.

这些库安装在C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64我认为vcvarsall.bat会设置一些指向它们的环境变量的地方 - 但显然它没有。更奇怪的是,当我从 VS 中配置 CMake 时,它​​不需要传递CMAKE_RC_COMPILERarg,但如果我不传递,那么它会失败,说明rc.exe找不到。

显然 VS 在配置 CMake 之前在后台进行了一些额外的配置 - 它是什么!?


作为一个额外的数据点,如果我尝试在 'Developer Powershell for VS 2022' 中运行上述 CMake 配置命令,它会因不同的原因而失败:

-- 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.
4

0 回答 0