Ros*_*ina 8 clang visual-studio-2019
我正在尝试从命令提示符访问 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.
Run Code Online (Sandbox Code Playgroud)
2020 年 2 月 26 日更新:微软仍然没有满意的答复。您可以在以下网址查看 Microsoft 的未答复并为此问题投票:https : //developercommunity.visualstudio.com/idea/875419/how-to-use-msvc-installed-c-clang-tools-for-window.html
这并不理想。
根据Visualstudio.com上的这篇文章,他们忘记添加某个环境变量或其本身的路径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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2137 次 |
| 最近记录: |