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?
2 Answers
Answers 1
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.
Answers 2
I'd suggest using MS's own tool for locating cl.exe. I've used this in the past and it helps with newer versions of VisualStudio too....
0 comments:
Post a Comment