使用 Visual Studio 11 编译的可执行文件有何特殊之处导致无法在 Windows XP 上执行?
我使用 Visual Studio 11 Developer Preview 编译 C++ 源代码。我静态链接到运行时库。
生成的可执行文件无法在 Windows XP 上执行。当我尝试在 Windows XP 上执行它时,收到错误消息“[可执行路径]不是有效的 Win32 应用程序。”。
根据 Microsoft 的说法 Visual Studio 11 不支持 Windows XP。
生成的可执行文件无法在 Windows XP 上执行,这是怎么回事?可执行文件中有什么特别的吗?
I compile my C++ source code with Visual Studio 11 Developer Preview. I statically link to the runtime library.
The resulting executable cannot be executed on Windows XP. When I try to execute it on Windows XP I get the error message "[Executable Path] is not a valid Win32 Application.".
According to Microsoft Visual Studio 11 won't support Windows XP.
How does it work that the resulting executable cannot be executed on Windows XP? Is there anything special within the executable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
他们似乎在每个新版本的 VS 中都放弃了对旧系统的支持(NT4、2000、XP< /a>) 即使您根本不使用 CRT,它们仍然会强制 PE 子系统版本为高数字。您可以通过在构建后步骤中将数字改回到 5.0 来解决此问题。只需更改这些数字就可以让 exe 在 XP 上启动,除非新的 CRT 使用 XP 上不存在的 WinAPI 函数。
如果您想继续使用 VS11,另一种选择是使用多目标和较旧的编译器......
They seem to drop support for older systems in every new release of VS (NT4,2000,XP) Even if you don't use the CRT at all, they still force the PE subsystem version to high numbers. You can work around that by changing the numbers back to 5.0 in a post build step. Just changing those numbers should allow the exe to start on XP unless the new CRT is using WinAPI functions that don't exist on XP.
The other alternative if you want to keep using VS11 is to use multi-targeting and older compilers...
Visual Studio 2012 将能够在 2012 年晚些时候以 Windows XP 为目标:
以 Windows XP 为目标Visual Studio 2012 中的 C++
“今年秋天晚些时候,Microsoft 将提供 Visual Studio 2012 的更新,使 C++ 应用程序能够瞄准Windows XP。此更新将对 Visual C++ 2012 编译器、运行时和库进行必要的修改,以便开发人员能够创建在 Windows XP 及更高版本以及 Windows Server 2003 及更高版本上运行的应用程序和 DLL。”
编辑:现在已经发生了(唷!)
Visual Studio 2012 will be able to target Windows XP later in 2012:
Targeting Windows XP with C++ in Visual Studio 2012
"Later this fall, Microsoft will provide an update to Visual Studio 2012 that will enable C++ applications to target Windows XP. This update will make the necessary modifications to the Visual C++ 2012 compiler, runtime, and libraries to enable developers to create applications and DLLs that run on Windows XP and higher versions as well as Windows Server 2003 and higher."
Edit: This has now happened (phew!)
解决方法是使用不同的
平台工具集
,它将链接不同版本的 CRT 并生成与旧操作系统兼容的二进制文件。请在此处查看更多信息:Visual Studio 11 Beta 中的目标 Windows XP使用 Visual Studio 2010 编译器和库。
使用
v90
工具集,您的二进制文件甚至可以在较旧的系统(例如 Windows 2000)中运行。http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7444.BlogPic.png
The workaround is to use a different
Platform Toolset
, which will link a different version of CRT and produce binaries compatible to older operating systems.See more here: Target Windows XP in Visual Studio 11 Beta using the Visual Studio 2010 compiler and libraries.
With
v90
toolset your binary will be able to run even in older systems, such as Windows 2000.http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69/7444.BlogPic.png
与 VS 2010 及更高版本捆绑的运行时库强制您的可执行文件从 kernel32.dll 导入 Windows XP 上缺少的两个新函数:
EncodePointer
和DecodePointer
。这些是增强软件“安全性”的又一白痴天真的尝试所需要的。在VS 2010中,有一个选项可以使用Visual Studio 2008的运行时库,它解决了这个问题。不知道VS以后的版本是否有这样的选项。
The runtime libraries bundled with VS 2010 and higher enforce your executable to import two new functions from kernel32.dll that are missing on Windows XP:
EncodePointer
andDecodePointer
. Those are needed for yet anotheridioticnaive attempt to enhance the software "security".In VS 2010 there is an option to use the runtime libraries of Visual Studio 2008, which solves this problem. I don't know if there's such an option in later versions of VS.