1

命令行中选择VC编译器版本

 1 year ago
source link: https://blog.csdn.net/yanxiangtianji/article/details/129415176
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

命令行中选择VC编译器版本_yanxiangtianji的博客-CSDN博客

有些时候需要安装多个版本的VC编译器。我们可以很方便的用Visual Studio Installer来把它们作为独立组件安装进来,,在图形界面里面也可以方便地在项目属性里修改编译器版本。但是命令行下切换就会比较麻烦,因为默认情况下开启的命令行只会加载最新版本的编译器。除非你完整地安装了多个版本的Visual Studio。

经过查阅微软文档,我发现可以用vcvarsall.bat这个工具手动加载特定版本的VC编译器。

众所周知,安装完VS之后,开始菜单中VS下面会有4个命令行快捷启动项,它们分别加载了特定架构(版本)的vc编译器。如果打开它们对应的文件会发现,它们本质是就是用特定参数运行vcvarsall.bat。比如native 64编译器就是运行vcvarsall.bar x64

vcvarsall.bat除了支持指定架构还支持指定平台、windows sdk版本、vc版本等。启动参数如下:

vcvarsall.bat [architecture] [platform_type] [winsdk_version] [-vcvars_ver=vcversion] [spectre_mode]

其中平台主要是指windows store/uwp版本还是普通的桌面程序,我们不用管它。我们主要会用到的是winsdk_versionvcvars_ver
需要注意的是winsdk_version是占位参数(必须是第三个),而vcvars_ver是具名参数,即必须写-vcvars_ver=xxx的形式。
这里的vc版本使用的是build版本号,这里支持简写自动匹配和tab自动补全。所以不用担心增加记忆量。下面是官网上给的3种情况的例子。

Use -vcvars_ver=14.2x.yyyyy to specify a specific version of the Visual Studio 2019 compiler toolset.

Use -vcvars_ver=14.29 to specify the latest version of the Visual Studio 2019 compiler toolset.

Use -vcvars_ver=14.0 to specify the Visual Studio 2015 compiler toolset.

假设VS安装在F:\Program Files\Microsoft Visual Studio\2022,我们还安装了最新的VS2019的编译工具(build号14.29.16.11,可以在F:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build中看到)。
我们具体使用的时候可以在命令行输入:

“F:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat” x64 -vcvars_ver=14.29

这里我启动了一个64位的VC2019编译环境。注意由于安装路径中包含有空格,所以需要使用引号将路径括起来。

更详细的介绍可以参考vcvarsall.bat官方文档:
https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#vcvarsall-syntax


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK