My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio 2005 Express edition. From time to time I have sent release .exe files to other people with pleasing results. However recently I made the disturbing discovery that the pleasing results were based on more luck that I would like. Attempting to run one of these programs on an old (2001 vintage, not scrupulously updated) XP box gave me nothing but a nasty "System cannot run x.exe" (or similar) message.

Some googling revealed that with this toolset, even specifying static linking results in a simple hello-world.exe actually relying on extra .dll files (msvcm80.dll etc.). An incredibly elaborate version scheming system (manifest files anyone?) then will not let the .exe run without exactly the right .dll versions. I don't want or need this stuff, I just want an old fashioned self contained .exe that does nothing but lowest common denominator Win32 operations and runs on any old win32 OS.

Does anyone know if its possible to do what I want to do with my existing toolset ?

Thank you.

+6  A: 

For the C-runtime go to the project settings, choose C/C++ then 'Code Generation'. Change the 'runtime library' setting to 'multithreaded' instead of 'multithreaded dll'.

If you are using any other libraries you may need to tell the linker to ignore the dynamically linked CRT explicitly.

Rob Walker
"If you are using any other libraries you may need to tell the linker to ignore the dynamically linked CRT explicitly." Recently I ran into this issue. I was building a wxWidgets app, I found I needed to rebuild the wxWidgets libs with the same code generation modification
Bill Forster
Man 300 characters isn't many. In case the comment above is unclear, the problem is that both your .cpp files and any library .cpp files need to have 'multithreaded' instead of 'multithreaded dll' else you might get link errors.
Bill Forster
+2  A: 

I've had this same dependency problem and I also know that you can include the VS 8.0 DLLs (release only! not debug!---and your program has to be release, too) in a folder of the appropriate name, in the parent folder with your .exe:

How to: Deploy using XCopy (MSDN)

Also note that things are guaranteed to go awry if you need to have C++ and C code in the same statically linked .exe because you will get linker conflicts that can only be resolved by ignoring the correct libXXX.lib and then linking dynamically (DLLs).

Lastly, with a different toolset (VC++ 6.0) things "just work", since Windows 2000 and above have the correct DLLs installed.

Jared Updike
+1  A: 

Thanks for the amazingly quick and useful (especially Rob Walker's) responses. I have now tried this out and it works very nicely. To help potential googlers find this answer I will quote the exact annoying message "The system cannot execute the specified program". I find googling for exact error messages a useful technique anyway.

Bill Forster