vs2013 命令行nmake中使用 v120_xp 工具

找到两个方法第一种参考 

在VS2013命令行中编译兼容XP的程序

 

Targeting from the Command Line

Visual Studio 2012 solutions and projects which have been switched to the v110_xp toolset can be built from the command line using MSBuild or DEVENV without additional steps. 

However, if you wish to use CL and Link directly, additional steps are needed. Note that the steps below may be automated by creating a batch script.

  1. Set the path and environment variables for Visual Studio 2012 command-line builds. 
  2. Set the required SDK paths and compiler flags using the following commands:

    set INCLUDE=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%
    set PATH=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%
    set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%
    set CL=/D_USING_V110_SDK71_;%CL%

    When targeting x64, set the lib path as follows:
    set LIB=%ProgramFiles(x86)%\Microsoft SDKs\Windows\7.1A\Lib\x64;%LIB%
     

  3. Specify the correct subsystem and subsystem version for the linker based on the type of application you are building. Applications targeting the x86 version of Windows XP must specify subsystem version 5.01, and applications targeting x64 must specify version 5.02.

    For x86 console applications: 
    set LINK=/SUBSYSTEM:CONSOLE,5.01 %LINK%

    For x64 console applications:
    set LINK=/SUBSYSTEM:CONSOLE,5.02 %LINK%
     

  4. Execute CL and Link as you normally would within the command prompt.

 

在VS2013的解决方案中设置兼容XP比较简单,在项目的 属性-常规-平台工具集 中选择 v120_xp 即可。但如果是使用VS的命令行来编译某些程序时,要怎么办呢? 在网上找到了一些资料,新建一个.bat文件,在VS命令行中首先执行一下它设置好环境即可。

@echo off
goto :start

:check_dir
    if not exist "%~1" (
        echo Directory "%~1" does not exist.
        echo Things may not work as expected.
    )
    goto :eof

:start
    setlocal
    if "%PROCESSOR_ARCHITECTURE%" == "x86" (
        set "ProgramFiles(x86)=%ProgramFiles%"
    )

    set "BINDIR=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Bin"
    set "INCDIR=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Include"
    set "LIBDIR=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib"
    set "SUBSYS=CONSOLE,5.01"

    REM for x64 instead of x86:
    REM set "LIBDIR=%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.1A\Lib\x64"
    REM set "SUBSYS=CONSOLE,5.02"

    call :check_dir "%%BINDIR%%"
    call :check_dir "%%INCDIR%%"
    call :check_dir "%%LIBDIR%%"

    endlocal & (
        set "CL=/D_USING_V110_SDK71_;%CL%"
        set "LINK=/SUBSYSTEM:%SUBSYS% %LINK%"
        set "LIB=%LIBDIR%;%LIB%"
        set "PATH=%BINDIR%;%PATH%"
        set "INCLUDE=%INCDIR%;%INCLUDE%"
    )

 

第二种:在“开始菜单”中运行  VS2013 x86 Native Tools Command Prompt 工具

RELEASE VERSION
nmake -f makefile.vc BUILD=release SHARED=1 CFLAGS=/D_USING_V120_SDK71_ CXXFLAGS=/D_USING_V120_SDK71_

DEBUG VERSION
nmake -f makefile.vc BUILD=debug SHARED=1 CFLAGS=/D_USING_V120_SDK71_ CXXFLAGS=/D_USING_V120_SDK71_

其中,makefile.vc 是基于nmake 的makefile 文件

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值