views:

445

answers:

2

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 there something else required to run MSVC compiled programs or a different compiler option or something else?

+8  A: 

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 Madsen
Also, the option to change to a statically linked runtime might work nicely.
Michael Burr
Or, alternatively, compile with static runtime libraries: go to "Project Properties -> C/C++ -> Code Generation -> Runtime Library", and pick the option without "DLL" in the name.
Pavel Minaev
Accepted: That's perfect.
Jon Cage
+3  A: 

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.

Pavel Minaev