不安装Visual Studio,只用Windows SDK搭建VC环境 博客分类: c++tools c++tools
首先你需要下载的是
Microsoft Windows SDK for Windows 7 and .NET Framework 4. 下载以后你得到的是一个网络安装文件,确保网络的连接,安装Windows SDK 7.1 (注意得到的Windows SDK 版本是7.1,这和我们安装Vsiual Studio得到的SDK 版本v7.0A是不一样的);
安装界面如下:
安装结束以后你应该得到如下的
1. 在c:\Program Files\Microsoft Visual Studio 10.0,你会看到不完全的Visual Studio的安装(主要是VC的库和头文件)
2.在C:\Program Files\Microsoft SDKs\Windows\v7.1,你会看到Windows SDK的安装。
3. 在C:\Windows\Microsoft.NET,你会看到各个版本的Framework 的安装
4. 在HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7,你会看到如下的值
“10.0” “C:\Program Files\Microsoft Visual Studio 10.0\VC\”
“FrameworkDir32" “C:\Windows\Microsoft.NET\Framework\”
“FrameworkDir64" “C:\Windows\Microsoft.NET\Framework64”
"Framework32Ver” “v4.0.30319”
"Framework64Ver” “v4.0.30319”
但是这样你还是不能运行vc++环境。首先你不能再PATH路径找到nmake,cl,而且,即使把cl加到了PATH路径中, 你也不能正确的运行编译,你需要一个脚本来初始化设置;
在c:\Program Files\Microsoft Visual Studio 10.0中,有两个文件可以用来初始化环境,一个是Common7\Tools\vsvars32.bat,另一个是VC\vcvarsall.bat;
但是这两个文件需要更改,因为
1. 该文件查询注册HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7 表找寻VS的安装目录,但是HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7只有在完全安装Visual studio以后才存在。你需要的是通过HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7,通过去掉结尾的VC\来间接的找到VS的安装目录。
:GetVSCommonToolsDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) )
2.文件查询HKLM\SOFTWARE\Microsoft SDKs\Windows\v7.0A来确定Windows SDK的安装目录,但是 该目录是安装Visual Studio时候才会安装的较低版本,安装了Windows SDK和Framework以后的Windows SDK版本更高,是v7.1;
:GetWindowsSdkDirHelper @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" /v "InstallationFolder"') DO ( @if "%%i"=="InstallationFolder" ( @SET "WindowsSdkDir=%%k" ) )
为了设置vc环境变量,我创建了my_vcvarsall.bat,内容如下:
@echo off if "%1" == "" goto x86 if not "%2" == "" goto usage if /i %1 == x86 goto x86 if /i %1 == amd64 goto amd64 if /i %1 == x64 goto amd64 if /i %1 == ia64 goto ia64 if /i %1 == x86_amd64 goto x86_amd64 if /i %1 == x86_ia64 goto x86_ia64 goto usage :x86 if not exist "%~dp0bin\my_vcvars32.bat" goto missing call "%~dp0bin\my_vcvars32.bat" goto :eof :amd64 if not exist "%~dp0bin\amd64\vcvars64.bat" goto missing call "%~dp0bin\amd64\vcvars64.bat" goto :eof :ia64 if not exist "%~dp0bin\ia64\vcvars64.bat" goto missing call "%~dp0bin\ia64\vcvars64.bat" goto :eof :x86_amd64 if not exist "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat" goto missing call "%~dp0bin\x86_amd64\vcvarsx86_amd64.bat" goto :eof :x86_ia64 if not exist "%~dp0bin\x86_ia64\vcvarsx86_ia64.bat" goto missing call "%~dp0bin\x86_ia64\vcvarsx86_ia64.bat" goto :eof :usage echo Error in script usage. The correct usage is: echo %0 [option] echo where [option] is: x86 ^| ia64 ^| amd64 ^| x86_amd64 ^| x86_ia64 echo: echo For example: echo %0 x86_ia64 goto :eof :missing echo The specified configuration type is missing. The tools for the echo configuration might not be installed. goto :eof
该文件会调用%~dp0bin\my_vcvars32.bat,,该文件的内容如下
@echo Setting environment for using Microsoft Visual Studio 2010 x86 tools. @call :GetVSCommonToolsDir @if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR @call "%VS100COMNTOOLS%my_VCVarsQueryRegistry.bat" 32bit No64bit @if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR @if "%FrameworkDir32%"=="" goto error_no_FrameworkDIR32 @if "%FrameworkVersion32%"=="" goto error_no_FrameworkVer32 @if "%Framework35Version%"=="" goto error_no_Framework35Version @set FrameworkDir=%FrameworkDir32% @set FrameworkVersion=%FrameworkVersion32% @if not "%WindowsSdkDir%" == "" ( @set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%" @set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%" @set "LIB=%WindowsSdkDir%lib;%LIB%" ) @rem @rem Root of Visual Studio IDE installed files. @rem @set DevEnvDir=%VSINSTALLDIR%Common7\IDE\ @rem PATH @rem ---- @if exist "%VSINSTALLDIR%Team Tools\Performance Tools" ( @set "PATH=%VSINSTALLDIR%Team Tools\Performance Tools;%PATH%" ) @if exist "%ProgramFiles%\HTML Help Workshop" set PATH=%ProgramFiles%\HTML Help Workshop;%PATH% @if exist "%ProgramFiles(x86)%\HTML Help Workshop" set PATH=%ProgramFiles(x86)%\HTML Help Workshop;%PATH% @if exist "%VCINSTALLDIR%VCPackages" set PATH=%VCINSTALLDIR%VCPackages;%PATH% @set PATH=%FrameworkDir%%Framework35Version%;%PATH% @set PATH=%FrameworkDir%%FrameworkVersion%;%PATH% @set PATH=%VSINSTALLDIR%Common7\Tools;%PATH% @if exist "%VCINSTALLDIR%BIN" set PATH=%VCINSTALLDIR%BIN;%PATH% @set PATH=%DevEnvDir%;%PATH% @if exist "%VSINSTALLDIR%VSTSDB\Deploy" ( @set "PATH=%VSINSTALLDIR%VSTSDB\Deploy;%PATH%" ) @if not "%FSHARPINSTALLDIR%" == "" ( @set "PATH=%FSHARPINSTALLDIR%;%PATH%" ) @rem INCLUDE @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE% @if exist "%VCINSTALLDIR%INCLUDE" set INCLUDE=%VCINSTALLDIR%INCLUDE;%INCLUDE% @rem LIB @rem --- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIB=%VCINSTALLDIR%ATLMFC\LIB;%LIB% @if exist "%VCINSTALLDIR%LIB" set LIB=%VCINSTALLDIR%LIB;%LIB% @rem LIBPATH @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIBPATH=%VCINSTALLDIR%ATLMFC\LIB;%LIBPATH% @if exist "%VCINSTALLDIR%LIB" set LIBPATH=%VCINSTALLDIR%LIB;%LIBPATH% @set LIBPATH=%FrameworkDir%%Framework35Version%;%LIBPATH% @set LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH% @goto end @REM ----------------------------------------------------------------------- :GetVSCommonToolsDir @set VS100COMNTOOLS= @call :GetVSCommonToolsDirHelper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetVSCommonToolsDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) echo SET "VS100COMNTOOLS=%VS100COMNTOOLS:VC\=%" @SET "VS100COMNTOOLS=%VS100COMNTOOLS:VC\=%" @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 :GetVSCommonToolsDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VS100COMNTOOLS=%%k" ) ) @SET "VS100COMNTOOLS=%VS100COMNTOOLS:VC\=%" @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 @REM ----------------------------------------------------------------------- :error_no_VS100COMNTOOLSDIR @echo ERROR: Cannot determine the location of the VS Common Tools folder. @goto end :error_no_VSINSTALLDIR @echo ERROR: Cannot determine the location of the VS installation. @goto end :error_no_FrameworkDIR32 @echo ERROR: Cannot determine the location of the .NET Framework 32bit installation. @goto end :error_no_FrameworkVer32 @echo ERROR: Cannot determine the version of the .NET Framework 32bit installation. @goto end :error_no_Framework35Version @echo ERROR: Cannot determine the .NET Framework 3.5 version. @goto end :end
该文件会调用Common7\Tools\my_VCVarsQueryRegistry.bat文件, 该文件内容是
@call :GetWindowsSdkDir @call :GetVSInstallDir @call :GetVCInstallDir @call :GetFSharpInstallDir @if "%1"=="32bit" ( @call :GetFrameworkDir32 @call :GetFrameworkVer32 ) @if "%2"=="64bit" ( @call :GetFrameworkDir64 @call :GetFrameworkVer64 ) @SET Framework35Version=v3.5 @goto end @REM ----------------------------------------------------------------------- :GetWindowsSdkDir @set WindowsSdkDir= @call :GetWindowsSdkDirHelper HKLM > nul 2>&1 @if errorlevel 1 call :GetWindowsSdkDirHelper HKCU > nul 2>&1 @if errorlevel 1 set WindowsSdkDir=%VCINSTALLDIR%\PlatformSDK\ @exit /B 0 :GetWindowsSdkDirHelper @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows \v7.1" /v "InstallationFolder"') DO ( @if "%%i"=="InstallationFolder" ( @SET "WindowsSdkDir=%%k" ) ) @if "%WindowsSdkDir%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetVSInstallDir @set VSINSTALLDIR= @call :GetVSInstallDirHelper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSInstallDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetVSInstallDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSInstallDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetVSInstallDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "L_VCINSTALLDIR=%%k" ) ) @SET "VSINSTALLDIR=%L_VCINSTALLDIR:VC\=%" @if "%VSINSTALLDIR%"=="" exit /B 1 @exit /B 0 :GetVSInstallDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "10.0"') DO ( @if "%%i"=="10.0" ( SET "L_VS100VCInstallDirs=%%k" SET "VSINSTALLDIR=%L_VS100VCInstallDirs:VC\=%" ) ) @if "%VSINSTALLDIR%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :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 "10.0"') DO ( @if "%%i"=="10.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 "10.0"') DO ( @if "%%i"=="10.0" ( @SET "VCINSTALLDIR=%%k" ) ) @if "%VCINSTALLDIR%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetFSharpInstallDir @set FSHARPINSTALLDIR= @call :GetFSharpInstallDirHelper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetFSharpInstallDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetFSharpInstallDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetFSharpInstallDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetFSharpInstallDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\10.0\Setup\F#" /v "ProductDir"') DO ( @if "%%i"=="ProductDir" ( @SET "FSHARPINSTALLDIR=%%k" ) ) @if "%FSHARPINSTALLDIR%"=="" exit /B 1 @exit /B 0 :GetFSharpInstallDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \10.0\Setup\F#" /v "ProductDir"') DO ( @if "%%i"=="ProductDir" ( @SET "FSHARPINSTALLDIR=%%k" ) ) @if "%FSHARPINSTALLDIR%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetFrameworkDir32 @set FrameworkDir32= @call :GetFrameworkDir32Helper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir32Helper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir32Helper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir32Helper64 HKCU > nul 2>&1 @exit /B 0 :GetFrameworkDir32Helper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "FrameworkDir32"') DO ( @if "%%i"=="FrameworkDir32" ( @SET "FrameworkDIR32=%%k" ) ) @if "%FrameworkDir32%"=="" exit /B 1 @exit /B 0 :GetFrameworkDir32Helper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "FrameworkDir32"') DO ( @if "%%i"=="FrameworkDir32" ( @SET "FrameworkDIR32=%%k" ) ) @if "%FrameworkDIR32%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetFrameworkb64 @set FrameworkDir64= @call :GetFrameworkDir64Helper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir64Helper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir64Helper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkDir64Helper64 HKCU > nul 2>&1 @exit /B 0 :GetFrameworkDir64Helper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "FrameworkDir64"') DO ( @if "%%i"=="FrameworkDir64" ( @SET "FrameworkDIR64=%%k" ) ) @if "%FrameworkDIR64%"=="" exit /B 1 @exit /B 0 :GetFrameworkDir64Helper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "FrameworkDir64"') DO ( @if "%%i"=="FrameworkDir64" ( @SET "FrameworkDIR64=%%k" ) ) @if "%FrameworkDIR64%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetFrameworkVer32 @set FrameworkVer32= @call :GetFrameworkVer32Helper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer32Helper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer32Helper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer32Helper64 HKCU > nul 2>&1 @exit /B 0 :GetFrameworkVer32Helper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "FrameworkVer32"') DO ( @if "%%i"=="FrameworkVer32" ( @SET "FrameworkVersion32=%%k" ) ) @if "%FrameworkVersion32%"=="" exit /B 1 @exit /B 0 :GetFrameworkVer32Helper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "FrameworkVer32"') DO ( @if "%%i"=="FrameworkVer32" ( @SET "FrameworkVersion32=%%k" ) ) @if "%FrameworkVersion32%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :GetFrameworkVer64 @set FrameworkVer64= @call :GetFrameworkVer64Helper32 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer64Helper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer64Helper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetFrameworkVer64Helper64 HKCU > nul 2>&1 @exit /B 0 :GetFrameworkVer64Helper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "FrameworkVer64"') DO ( @if "%%i"=="FrameworkVer64" ( @SET "FrameworkVersion64=%%k" ) ) @if "%FrameworkVersion64%"=="" exit /B 1 @exit /B 0 :GetFrameworkVer64Helper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "FrameworkVer64"') DO ( @if "%%i"=="FrameworkVer64" ( @SET "FrameworkVersion64=%%k" ) ) @if "%FrameworkVersion64%"=="" exit /B 1 @exit /B 0 @REM ----------------------------------------------------------------------- :end
至此,你可以起一个命令行,在代码里面敲入:
C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
然后,就可以运行nmake,比如说来编译ruby的文件了。
如果你只是需要设置C#的环境,你需要修改\添加Common7\Tools\my_vsvars32.bat,该文件的内容如下
@echo Setting environment for using Microsoft Visual Studio 2010 x86 tools. @call :GetVSCommonToolsDir @if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR @call "%VS100COMNTOOLS%my_VCVarsQueryRegistry.bat" 32bit No64bit @if "%VSINSTALLDIR%"=="" goto error_no_VSINSTALLDIR @if "%FrameworkDir32%"=="" goto error_no_FrameworkDIR32 @if "%FrameworkVersion32%"=="" goto error_no_FrameworkVer32 @if "%Framework35Version%"=="" goto error_no_Framework35Version @set FrameworkDir=%FrameworkDir32% @set FrameworkVersion=%FrameworkVersion32% @if not "%WindowsSdkDir%" == "" ( @set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%" @set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%" @set "LIB=%WindowsSdkDir%lib;%LIB%" ) @rem @rem Root of Visual Studio IDE installed files. @rem @set DevEnvDir=%VSINSTALLDIR%Common7\IDE\ @rem PATH @rem ---- @if exist "%VSINSTALLDIR%Team Tools\Performance Tools" ( @set "PATH=%VSINSTALLDIR%Team Tools\Performance Tools;%PATH%" ) @if exist "%ProgramFiles%\HTML Help Workshop" set PATH=%ProgramFiles%\HTML Help Workshop; %PATH% @if exist "%ProgramFiles(x86)%\HTML Help Workshop" set PATH=%ProgramFiles(x86)%\HTML Help Workshop;%PATH% @if exist "%VCINSTALLDIR%VCPackages" set PATH=%VCINSTALLDIR%VCPackages;%PATH% @set PATH=%FrameworkDir%%Framework35Version%;%PATH% @set PATH=%FrameworkDir%%FrameworkVersion%;%PATH% @set PATH=%VSINSTALLDIR%Common7\Tools;%PATH% @if exist "%VCINSTALLDIR%BIN" set PATH=%VCINSTALLDIR%BIN;%PATH% @set PATH=%DevEnvDir%;%PATH% @if exist "%VSINSTALLDIR%VSTSDB\Deploy" ( @set "PATH=%VSINSTALLDIR%VSTSDB\Deploy;%PATH%" ) @if not "%FSHARPINSTALLDIR%" == "" ( @set "PATH=%FSHARPINSTALLDIR%;%PATH%" ) @rem INCLUDE @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\INCLUDE" set INCLUDE=%VCINSTALLDIR%ATLMFC\INCLUDE;%INCLUDE% @if exist "%VCINSTALLDIR%INCLUDE" set INCLUDE=%VCINSTALLDIR%INCLUDE;%INCLUDE% @rem LIB @rem --- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIB=%VCINSTALLDIR%ATLMFC\LIB;%LIB% @if exist "%VCINSTALLDIR%LIB" set LIB=%VCINSTALLDIR%LIB;%LIB% @rem LIBPATH @rem ------- @if exist "%VCINSTALLDIR%ATLMFC\LIB" set LIBPATH=%VCINSTALLDIR%ATLMFC\LIB;%LIBPATH% @if exist "%VCINSTALLDIR%LIB" set LIBPATH=%VCINSTALLDIR%LIB;%LIBPATH% @set LIBPATH=%FrameworkDir%%Framework35Version%;%LIBPATH% @set LIBPATH=%FrameworkDir%%FrameworkVersion%;%LIBPATH% @goto end @REM ----------------------------------------------------------------------- :GetVSCommonToolsDir @set VS100COMNTOOLS= @call :GetVSCommonToolsDirHelper32 HKLM > nul 2>&1 @rem call :GetVSCommonToolsDirHelper32 HKLM @if errorlevel 1 call :GetVSCommonToolsDirHelper32 HKCU > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKLM > nul 2>&1 @if errorlevel 1 call :GetVSCommonToolsDirHelper64 HKCU > nul 2>&1 @exit /B 0 :GetVSCommonToolsDirHelper32 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\VisualStudio\SxS\VC7" /v "10.0"') DO ( @if "%%i"=="10.0" ( @SET "L_VS100VCInstallDirs=%%k" ) ) @echo SET "VS100COMNTOOLS=%L_VS100VCInstallDirs:VC\=%" @SET "VS100COMNTOOLS=%L_VS100VCInstallDirs:VC\=%" @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 :GetVSCommonToolsDirHelper64 @for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\VisualStudio \SxS\VC7" /v "10.0"') DO ( @if "%%i"=="10.0" ( SET "L_VS100VCInstallDirs=%%k" SET "VS100COMNTOOLS=%L_VS100VCInstalldirs:VC\=%" ) ) @if "%VS100COMNTOOLS%"=="" exit /B 1 @SET "VS100COMNTOOLS=%VS100COMNTOOLS%Common7\Tools\" @exit /B 0 @REM ----------------------------------------------------------------------- :error_no_VS100COMNTOOLSDIR @echo ERROR: Cannot determine the location of the VS Common Tools folder. @goto end :error_no_VSINSTALLDIR @echo ERROR: Cannot determine the location of the VS installation. @goto end :error_no_FrameworkDIR32 @echo ERROR: Cannot determine the location of the .NET Framework 32bit installation. @goto end :error_no_FrameworkVer32 @echo ERROR: Cannot determine the version of the .NET Framework 32bit installation. @goto end :error_no_Framework35Version @echo ERROR: Cannot determine the .NET Framework 3.5 version. @goto end :end
如代码所示,你Common7\Tools\my_vsvars32.bat 会调用Common7\Tools\my_VCVarsQueryRegistry.bat 的文件;my_VCVarsQueryRegistry.bat的文件内容在上面已经已经介绍了。
至此,所有的配置都已经结束,本文中的配置只是在win32 x85环境下测试过了,没有测试过amd64,但是思路是一样的,你可以按照类似的方法调试通过64的配置;
References: