自己动手制作VC++2010绿色版

自己动手制作VC++2010绿色版
文章分类:C++编程
绿色版本需求:不需要安装即可使用,干净不带IDE,不带其他语言C#、F#开发工具,不带SqlServer相关开发工具,不带.NET4 SDK,
整个包较原版安装包小,支持编译调试版本的程序,支持x86、x64、以及x86交叉编译x64应用程序。

制作环境:
Windows 7 ultimate中文版本。
VS2010安装在默认的C:/Program Files (x86)/Microsoft Visual Studio 10.0/目录。
绿化环境在Z:/VC2010/目录。

1. 到MicroSoft官方网站下载 MicroSoft Visual Studio 2010 retail 30天试用版本,安装时选择只安装VC++工具,
包括x64开发包,但不包括IA64开发包。
测试运行无误,准备完毕。这原版VC++2010战用磁盘5.5G左右。

2. 创建VC++2010绿色版基础目录结构。
Z:/VC2010/bin/
Z:/VC2010/lib/
Z:/VC2010/include/
Z:/VC2010/atlmfc/
Z:/VC2010/crt/
Z:/VC2010/PlatformSDK/
Z:/VC2010/redist/
Z:/VC2010/system32
Z:/VC2010/SysWOW64/
Z:/VC2010/ide/
Z:/VC2010/scripts/

3. 拷贝VC++2010基本包文件
注:下面的说明把C:/Program Files (x86)/Microsoft Visual Studio 10.0/简写为CPMS,
把C:/Program Files (x86)/ 简写为CPF86。
把CPMS/目录下的altmfc, include,bin,lib,crt,redist目录拷贝到Z:/VC2010/。
把CPF86/Microsoft SDKs/Windows/v7.0A/目录下的include,lib拷贝到Z:/VC2010/PlatformSDK/。
把CPF86/Microsoft SDKs/Windows/v7.0A/bin/目录下的mt.exe, mt.exe.config, rc.exe, rcdll.dll 四个文件拷贝到Z:/VC2010/PlatformSDK/。

4. 拷贝VC++2010中用到的附加库及程序
把C:/Windows/SysWOW64/msvcr100_clr0400.dll 拷贝到Z:/VC2010/SysWOW64/。
把C:/Windows/System32/msvcr100_clr0400.dll 拷贝到Z:/VC2010/system32/。
这两个文件是编译过程中COFF文件格式转换工具cvtres.exe使用的,x86,x64两个平台下使用两个不同的版本。

把CPMS/Common7/IDE/目录下的 msobj100.dll, mspdb100.dll, mspdbcore.dll, mspdbsrv.exe, mspdbst.dll 五个文件拷贝到Z:/VC2010/ide/。
这几个文件是编译调试版本的程序或者库时乃至的程序。

5. 编写VC++运行环境变量脚本。
一共有4个要编写的脚本,分别为,
Z:/VC2010/vc2010.bat 运行环境启动入口脚本。
Z:/VC2010/scripts/vcvars32.bat x86运行环境相关变量设置脚本。
Z:/VC2010/scripts/amd64/vcvars64.bat x64运行环境相关变量设置脚本。
Z:/VC2010/scripts/x86_amd64/vcvarsx86_amd64.bat 在x86平台上交叉编译x64程序或者库运行环境相关变量设置脚本。

这四个脚本都有参考脚本,可在原版安装目录中找到。

a) Z:/VC2010/vc2010.bat
主要是注册绿色版VC2010的安装目录,然后根据不同的参数确定不同的运行平台,调用下面对应平台上的环境设置脚本。
set VCINSTALLDIR=Z:/VC2010

@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 "%VCINSTALLDIR%/scripts/vcvars32.bat" goto missing
call "%VCINSTALLDIR%/scripts/vcvars32.bat"
goto :eof

:amd64
if not exist "%VCINSTALLDIR%/scripts//amd64/vcvars64.bat" goto missing
call "%VCINSTALLDIR%/scripts//amd64/vcvars64.bat"
goto :eof

:ia64
if not exist "%VCINSTALLDIR%/scripts/ia64/vcvars64.bat" goto missing
call "%VCINSTALLDIR%/scripts/ia64/vcvars64.bat"
goto :eof

:x86_amd64
if not exist "%VCINSTALLDIR%/scripts/x86_amd64/vcvarsx86_amd64.bat" goto missing
call "%VCINSTALLDIR%/scripts/x86_amd64/vcvarsx86_amd64.bat"
goto :eof

:x86_ia64
if not exist "%VCINSTALLDIR%/scripts/x86_ia64/vcvarsx86_ia64.bat" goto missing
call "%VCINSTALLDIR%/scripts/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

:eof


b) Z:/VC2010/scripts/vcvars32.bat
@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@echo Setting environment for using Microsoft Visual Studio 2010 x86 tools.

@set PATH=%VCINSTALLDIR%/BIN;%VCINSTALLDIR%/PlatformSDK/bin;%PATH%
@set PATH=%VCINSTALLDIR%/redist/x86/Microsoft.VC100.CRT/;%VCINSTALLDIR%/SysWOW64;%PATH%
@set PATH=%VCINSTALLDIR%/redist/Debug_NonRedist/x86/Microsoft.VC100.DebugCRT;%VCINSTALLDIR%/ide;%PATH%
@set INCLUDE=%VCINSTALLDIR%/ATLMFC/INCLUDE;%VCINSTALLDIR%/INCLUDE;%VCINSTALLDIR%/PlatformSDK/include;%INCLUDE%
@set LIB=%VCINSTALLDIR%/ATLMFC/LIB;%VCINSTALLDIR%/LIB;%VCINSTALLDIR%/PlatformSDK/lib;%LIB%
@set LIBPATH=%VCINSTALLDIR%/ATLMFC/LIB

@goto end


:error_no_VCINSTALLDIR
@echo ERROR: VCINSTALLDIR variable is not set.
@goto end

:end

c) Z:/VC2010/scripts/amd64/vcvars64.bat

@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@echo Setting environment for using Microsoft Visual Studio 2010 x64 tools.

@set PATH=%VCINSTALLDIR%/BIN/amd64;%VCINSTALLDIR%/PlatformSDK/bin/win64/amd64;%VCINSTALLDIR%/PlatformSDK/bin;%VCINSTALLDIR%/BIN;%PATH%
@set PATH=%VCINSTALLDIR%/redist/x64/Microsoft.VC100.CRT/;%VCINSTALLDIR%/System32;%PATH%
@set PATH=%VCINSTALLDIR%/redist/Debug_NonRedist/x64/Microsoft.VC100.DebugCRT;%VCINSTALLDIR%/ide;%PATH%
@set INCLUDE=%VCINSTALLDIR%/ATLMFC/INCLUDE;%VCINSTALLDIR%/INCLUDE;%VCINSTALLDIR%/PlatformSDK/include;%INCLUDE%
@set LIB=%VCINSTALLDIR%/ATLMFC/LIB/amd64;%VCINSTALLDIR%/LIB/amd64;%VCINSTALLDIR%/PlatformSDK/lib/x64;%LIB%

@set LIBPATH=%VCINSTALLDIR%/ATLMFC/LIB/amd64;%LIBPATH%

@goto end

:error_no_VCINSTALLDIR
@echo ERROR: VCINSTALLDIR variable is not set.
@goto end

:end


d) Z:/VC2010/scripts/x86_amd64/vcvarsx86_amd64.bat

@if "%VCINSTALLDIR%"=="" goto error_no_VCINSTALLDIR

@echo Setting environment for using Microsoft Visual Studio 2010 x64 cross tools.

@set PATH=%VCINSTALLDIR%/BIN/x86_amd64;%VCINSTALLDIR%/BIN;%VCINSTALLDIR%/PlatformSDK/bin;%PATH%
@set PATH=%VCINSTALLDIR%/redist/x86/Microsoft.VC100.CRT/;%VCINSTALLDIR%/SysWOW64;%PATH%
@set PATH=%VCINSTALLDIR%/redist/Debug_NonRedist/x86/Microsoft.VC100.DebugCRT;%VCINSTALLDIR%/ide;%PATH%
@set INCLUDE=%VCINSTALLDIR%/ATLMFC/INCLUDE;%VCINSTALLDIR%/INCLUDE;%VCINSTALLDIR%/PlatformSDK/include;%INCLUDE%
@set LIB=%VCINSTALLDIR%/ATLMFC/LIB/amd64;%VCINSTALLDIR%/LIB/amd64;%VCINSTALLDIR%/PlatformSDK/lib/amd64;%LIB%

@set LIBPATH=%VCINSTALLDIR%/ATLMFC/LIB/amd64;%LIBPATH%

@goto end

:error_no_VCINSTALLDIR
@echo ERROR: VCINSTALLDIR variable is not set.
@goto end

:end

6. 创建启动快捷方式。
一共有3个,分别为:
VC++2010_x86.lnk
VC++2010_x64.lnk
VC++2010_x86-amd64.lnk

i) VC2010_x86.lnk 属性设置
设置目标:%comspec% /k ""Z:/VC2010/vc2010.bat"" x86
起始位置:Z:/VC2010

ii) VC2010_x64.lnk 属性设置
设置目标:%comspec% /k ""Z:/VC2010/vc2010.bat"" amd64
起始位置:Z:/VC2010

iii) VC2010_x86-amd64.lnk 属性设置
设置目标:%comspec% /k ""Z:/VC2010/vc2010.bat"" x86_amd64
起始位置:Z:/VC2010

需要注意的是,这几个快捷方式的字体属性指定为NSimsun,不要使用点阵字体,否则在其他语言版本的系统上有问题。

现在需要使用不同环境的VC++2010只需要点击相应的启动快捷方式就可以进入对应环境的编译命令行了。

附后:
如果需要设置自定义的一些环境变量,可以修改vc2010.bat入口脚本头几行,设置可生效。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值