生而自由

自由而无用的灵魂

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

在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%"
    )

 

参考资料:

http://stackoverflow.com/questions/16075171/how-can-i-compile-for-windows-xp-with-visual-studio-2012-from-the-command-prompt

https://blogs.msdn.microsoft.com/vcblog/2012/10/08/windows-xp-targeting-with-c-in-visual-studio-2012/

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注