从命令提示符访问 Visual Studio 2019 版本 clang 的官方方法是什么?

问题描述 投票:0回答:1

我正在尝试从命令提示符访问 Visual Studio 2019 版本的 clang。我正在寻找“官方”的方式来做到这一点。到目前为止,它似乎没有记录在任何 MSVC/clang 博客文章 中。 (请注意,我不是正在寻找在 Windows 上构建/安装 clang 的其他方法。这个问题特别与 VS2019 clang 组件相关。) 使用 Visual Studio 安装程序,我安装了 Visual Studio 2019 Professional(版本 16.4.1)以及可选的“适用于 Windows 的 C++ Clang 工具(9.0.0 - x64/x86)”。 clang 工具链似乎安装在:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\Llvm\bin


(也许我可以将此目录添加到 PATH,但这并不可靠。我也找不到任何 Microsoft 文档中记录的这种方法。)

我的最终目标是将

clang-cl

与 scons 一起使用。但作为第一步,我希望能够从命令提示符运行

clang-cl

当我运行

vcvarsall.bat

时,命令提示符下没有任何 clang 工具可用:


C:\Users\Ross>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" x64 ********************************************************************** ** Visual Studio 2019 Developer Command Prompt v16.4.1 ** Copyright (c) 2019 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64' C:\Users\Ross>cl Microsoft (R) C/C++ Optimizing Compiler Version 19.24.28314 for x64 Copyright (C) Microsoft Corporation. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ] C:\Users\Ross>clang 'clang' is not recognized as an internal or external command, operable program or batch file. C:\Users\Ross>clang++ 'clang++' is not recognized as an internal or external command, operable program or batch file. C:\Users\Ross>clangcl 'clangcl' is not recognized as an internal or external command, operable program or batch file. C:\Users\Ross>clang-cl 'clang-cl' is not recognized as an internal or external command, operable program or batch file.

2020 年 2 月 26 日更新:

微软仍然没有给出令人满意的答复。您可以查看 Microsoft 的非答复并为此问题投票:https://developercommunity.visualstudio.com/idea/875419/how-to-use-msvc-installed-c-clang-tools-for-window。 html

clang visual-studio-2019
1个回答
0
投票

根据

visualstudio.com

上的这篇文章,他们忘记添加某些 env 变量path 本身的路径。

但是,不要害怕,有一个简单而正确的方法使用

vswhere


function Get-VsWhere {
    param (
        [Parameter(ParameterSetName = "1")][String] $component,
        [Parameter(ParameterSetName = "1")][String] $find,
        [Parameter(ParameterSetName = "2")][String] $property
    )
    if (-not (Get-Command ./.build/vswhere.exe -ea Ignore)) {
        New-Item -ItemType Directory ./.build/ -Force | Out-Null
        Invoke-WebRequest https://github.com/microsoft/vswhere/releases/download/3.1.7/vswhere.exe -OutFile ./.build/vswhere.exe
    }
    $vswhere = (Get-Item ./.build/vswhere.exe).FullName
    if ($find) {
        & $vswhere -latest -requires $component -find $find
    }
    elseif ($property) {
        & $vswhere -latest -property $property
    }
}


function Get-Clang {
    if (-not $script:_clang) {
        $script:_clang = Get-VsWhere `
            -component Microsoft.VisualStudio.Component.VC.Llvm.Clang `
            -find '**/x64/**/clang.exe'
    }
    $script:_clang
}

$clang = Get-Clang
Add-PathVariable (Split-Path -Parent $clang)

# Add-PathVariable is from PSCX, it does what's on the label

© www.soinside.com 2019 - 2024. All rights reserved.