I would like to retrieve the full path to the compiler cl.exe
in Visual Studio to call it from a program. Do we have keys in the registry for that? How to do it?
Asked
Active
Viewed 1.6k times
10

Wai Ha Lee
- 8,598
- 83
- 57
- 92

stefv
- 429
- 1
- 4
- 19
-
You can have many versions of Visual Studio installed on a computer. Plus Visual Studio 2017 can be installed many times (with different types of licenses). Plus you can have many versions of the VC tools (cl.exe is part of "VC tools") for one Visual Studio 2017 setup. Can you refine your request? – Simon Mourier Jun 16 '18 at 09:14
-
I would like to list the path to all the cl.exe or to find a specific version of it from the CPU, the version, ... I have a program generating C++ language and I would like to call automatically the compiler with this C++ source code. – stefv Jun 18 '18 at 10:13
-
"I would like to list the path to all the cl.exe or to find a specific version of it from the CPU, the version, ..." So what's the problem with doing that using my answer? – n0p Jun 20 '18 at 13:22
1 Answers
8
cl.exe
is usually located at %VCINSTALLDIR%\bin\
. VCINSTALLDIR
environment variable is not set by default, but it is being set when you open Visual Studio's Native Tools Command Prompt.
Here is how it is done in that batch script:
:GetVCInstallDir
@set VCINSTALLDIR=
@call :GetVCInstallDirHelper32 HKLM > nul 2>&1
@if errorlevel 1 call :GetVCInstallDirHelper32 HKCU > nul 2>&1
@if errorlevel 1 call :GetVCInstallDirHelper64 HKLM > nul 2>&1
@if errorlevel 1 call :GetVCInstallDirHelper64 HKCU > nul 2>&1
@exit /B 0
:GetVCInstallDirHelper32
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "14.0"') DO (
@if "%%i"=="14.0" (
@SET VCINSTALLDIR=%%k
)
)
@if "%VCINSTALLDIR%"=="" exit /B 1
@exit /B 0
:GetVCInstallDirHelper64
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7" /v "14.0"') DO (
@if "%%i"=="14.0" (
@SET VCINSTALLDIR=%%k
)
)
@if "%VCINSTALLDIR%"=="" exit /B 1
@exit /B 0
So depending on bitness of the system it looks at one of these registry keys
32-bit
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VC7
if VS is installed system-wideHKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\SxS\VC7
if VS is installed for current user
64-bit
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7
if VS is installed system-wideHKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7
if VS is installed for current user
Then there you have strings for each installed version. This is how it looks on my machine:
It requires an extra work to programmatically retrieve the correct value if you don't know what version you want, but that is out of scope of this question.

n0p
- 713
- 10
- 23