4

I'm trying to find a way to invoke the Visual Studio C++ compiler (MSVC) from within my Git Bash terminal on Windows. The Developer Command Prompt for VS2017 works fine, it's just annoying to switch between windows just to compile my application.

I tried adding cl.exe to my Path and was unsuccessful. Google keeps pointing me toward using GCC, which I'm not interested in doing. I was also able to find these two questions, both about Cygwin, one about invoking cl.exe and another about importing vcvars32.bat funcationality (They're linked to each other). The issue is that 1) these are for Cygwin, not MINGW64, and 2) point me to vcvars32.bat/VsDevCmd.bat. That script seems to mainly be for setting up the development environment (It also passes all smoke tests invoked by VsDevCmd.bat if that matters.).

So my question(s) is/are:
Is this possible?
How do I resolve bash: cl: command not found and allow calling cl.exe from Git Bash?

Lord Drake
  • 172
  • 2
  • 12

2 Answers2

3

Simple workaround: launch your Git Bash terminal from inside a Developer Command Prompt terminal so that it inherits the environment.

Longer (but more flexible): Convert vcvars32.bat to a bash script and source it.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
3
C:\>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.8
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\>f:\git\usr\bin\bash.exe        

$ cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]
blabb
  • 8,674
  • 1
  • 18
  • 27