简体   繁体   English

Visual Studio 2012编译为XP - 无效的win32 - v110_xp

[英]Visual Studio 2012 compile for XP - not valid win32 - v110_xp

I have Visual Studio 2012 update 4 and the Windows SDK 7.1. 我有Visual Studio 2012更新4和Windows SDK 7.1。

I select the "Visual Studio 2012 - Windows XP (v110_xp)" toolkit and the include directories change to use $(WindowsSdkDir_71A). 我选择“Visual Studio 2012 - Windows XP(v110_xp)”工具包,并将include目录更改为使用$(WindowsSdkDir_71A)。

No errors are given during compile (eg it successfully finds winres.h), but when I try to run the exe on Windows XP SP3, it still errors: "test.exe is not a valid Win32 application." 在编译期间没有给出错误(例如它成功找到winres.h),但是当我尝试在Windows XP SP3上运行exe时,它仍然是错误:“test.exe不是有效的Win32应用程序。”

For testing, it's just a C++ hello world. 对于测试,它只是一个C ++ hello世界。

#include <cstdio>

int main(void)
{
    printf("Hello, World!\r\n");
    return 0;
}

How can I use Visual Studio 2012 to compile for XP? 如何使用Visual Studio 2012编译XP?

What should I check to get this working? 我应该检查什么才能使这个工作?

How can I test compile on the command line? 如何在命令行上测试编译? I'm currently testing on the command line with this, which still gives the invalid win32 error: 我目前正在测试命令行,这仍然会给出无效的win32错误:

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" /EHsc /MT /I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" /I"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include" main.cpp /link /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib" 

Update: It works if I use these instructions for the command line: http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx 更新:如果我在命令行中使用这些说明,它可以工作: http//blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx

If I put these settings into my system environment variables, I can also get msbuild and visual studio to compile successfully, but this is not ideal. 如果我将这些设置放入我的系统环境变量中,我也可以让msbuild和visual studio成功编译,但这并不理想。

The setting that needed to be changed was Project Properties -> Configuration Properties -> Linker -> System -> SubSystem 需要更改的设置是Project Properties - > Configuration Properties - > Linker - > System - > SubSystem

This needs to be set to CONSOLE or WINDOWS for the appropriate project type, but is not set by default for an "empty project", even if console vs GUI is set elsewhere and it appears to work (eg WinMain is the entry point, console does not appear, etc). 这需要针对相应的项目类型设置为CONSOLE或WINDOWS,但默认情况下不为“空项目”设置,即使控制台与GUI设置在其他位置并且它似乎有效(例如WinMain是入口点,控制台)没有出现等)。 Minimum Required Version also needs to be 5.01, but judging by the command line help on link.exe, I don't think this does anything unless subsystem is set. 最低要求版本也需要是5.01,但是通过link.exe上的命令行帮助来判断,除非设置了子系统,否则我认为这不会做任何事情。

Things to check: 要检查的事项:

  • Visual Studio 2012 is Update 1 or higher Visual Studio 2012是Update 1或更高版本
  • SDK 7.1 is installed and 7.1A exists 已安装SDK 7.1并且存在7.1A
  • the "Visual Studio 2012 - Windows XP (v110_xp)" toolkit is used 使用“Visual Studio 2012 - Windows XP(v110_xp)”工具包
  • the preprocessor definitions contains _USING_V110_SDK71_ 预处理程序定义包含_USING_V110_SDK71_
  • the VC++ Directories contain $(WindowsSdkDir_71A)bin, $(WindowsSdkDir_71A)include and $(WindowsSdkDir_71A)lib VC ++目录包含$(WindowsSdkDir_71A)bin,$(WindowsSdkDir_71A)include和$(WindowsSdkDir_71A)lib
  • linker subsystem is console or windows, with minimum required version 5.01 链接器子系统是控制台或窗口,所需的最低版本为5.01

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM