从 cmd 运行 cl.exe [英] Run cl.exe from cmd

查看:35
本文介绍了从 cmd 运行 cl.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 C++ 安装了 Visual Studio Community 2017.我想从 cmd 使用它的编译器.我可以从 Developer Command Prompt for VS 2017 使用它,但我无法从普通 cmd 使用它.我尝试通过 右键单击​​ -> 运行 vsvarsall.exe以管理员身份运行.但什么也没有发生.好像我必须手动设置环境变量.每当我尝试运行命令时

I have installed Visual Studio Community 2017 with C++. I wanted to use its compiler from cmd. I am able to use it from Developer Command Prompt for VS 2017 but I am unable to use it from normal cmd. I have tried running vsvarsall.exe by right click-> run as administrator. But nothing happens. Seems like I have to set environment variables manually. Whenever I try to run the command

cl hello.c

它说hello.c(1): fatal error C1034: stdio.h: no include path set

推荐答案

Visual Studio 包含一个批处理文件,用于为您准备环境(实际上,开发人员命令提示在后台调用它).

Visual Studio includes a batch file that prepares the environment for you (actually, the Developer Command Prompt calls it under-the-hood).

我从未尝试过社区版,但对于 VS 2017 Professional,它位于 "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat".当然,如果您更改了安装路径,它可能会有所不同.

I've never tried with the Community Edition, but for VS 2017 Professional it is located at "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat". It may vary if you changed the installation path, of course.

所以,你所要做的就是调用它:

So, all you have to do is to invoke it:

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"

应该会出现如下内容

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.3
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

之后,您可以像在 cmd 中一样调用 clnmakemsbuild.

After that you can invoke cl, nmake, msbuild as within cmd.

您也可以改为调用 vcvarsall.bat x86(vcvars32.bat 只是一个快捷方式).

You can also invoke vcvarsall.bat x86 instead (the vcvars32.bat is just a shortcut for that).

您可以通过创建一个自动调用它然后打开命令提示符的批处理来避免每次都输入它

You can avoid typing it each time by creating a batch that automatically invokes it and then open a command prompt

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"
cmd

然后运行该批处理而不是 cmd.

And then run that batch instead of cmd.

另一种选择是将 "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\" 添加到路径中,这样您只需键入 vcvars32.bat 当您需要开发者工具时.

Another option is to add the "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\" to the path so you only have to type vcvars32.bat when you need the developer tools.

这篇关于从 cmd 运行 cl.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆