How do I compile for windows XP under windows 7 / visual studio 2008
I'm running Windows 7 and Visual Studio 2008 Pro and trying to get my application to work on Windows XP SP3.
It's a really minimal command line program so should have any ridiculous dependencies:
// XPBuild.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello world");
getchar();
return 0;
}
I read somewhere that defining several constants such as WINVER should allow me to compile for other platforms. I've tried the added the following to my /D
compiler options:
;WINVER=0x0501;_WIN32_WINNT 0x0501;NTDDI_VERSION=NTDDI_WINXP
But that made no difference. When I run it on my Windows XP machine (actually running in a virtualbox) I get the following error:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
So what have I missed? Is th开发者_开发技巧ere something else required to run MSVC compiled programs or a different compiler option or something else?
What you have missed is most likely that VC++ programs require a runtime to be installed (unless you link statically, which is not the default) - the error message you show is exactly the one you get if they're not in order.
Try installing the Microsoft Visual C++ 2008 SP1 Redistributable Pack on the XP machine - you will most likely see that your program works with no changes whatsoever.
Michael's answer explains why it doesn't work for you, and what you should do about it. With respect to WINVER
- they don't change anything about your binary in a sense that it would suddenly start working on XP. What they do is disable function and type declarations in Windows headers files that are not supported on the OS version specified by WINVER
. This ensures that you do not accidentally call e.g. some Vista-only function. However, you don't strictly need it - if your code does not rely on any Vista/7-only functionality, you can compile without redefining WINVER
, and it'll still work fine on XP.
Just Set the compiler to use static linking in the project settings (Project -> Properties -> Config Properties -> C/C++ -> Code Generation -> Change "Runtime Library" to /MT or /MTd instead of the default /MD or /MDd)
精彩评论