views:

68

answers:

2

I'm doing a very small windows application consisting of just a single executable. As the program will reside on a SD card I want the application to be as self contained as possible, and I'd rather not have an installer. I'd want the user to be able to simply copy the executable to the SD card and be able to run it straight away without fiddling with anything extra. The problem then becomes the fact that my program is compiled with VS 2008 which requires versions of the CRT which I can't guarantee is installed. I'm linking statically to the CRT, which I incorrectly thought would circumvent this problem. I've been thinking of tracking down some older VS version, but I have a feeling this is the incorrect path. I want the program to run on a fresh install of windows xp and above.

Grateful for any help.

+3  A: 

Linking statically to the CRT using /MT or /MTd (for debug) should do exactly what you need.

The fact that it isn't suggest that there is still something that depends on the dynamic library. That would be the case if you has some additional DLLs which are not compiled with the static CRT.

you can use the dependency walker (depends.exe) to figure out exactly which dlls use which and who still depends on the dynamic CRT or in any other DLL.

Another approach is to run your exe from the debugger and see which DLLs are being loaded in the output window. Which depends.exe gives you only the dlls loaded on the startup, this can give you some additional dependencies that are loaded only on runtime.

shoosh
Unfortunately the dependency walk or debugger methods are not sufficient. When the CRT libraries are loaded dynamically they perform some checks. You need to have the assembly manifest file present and every member of the assembly present (whether or not it is actually needed) or they generate something like "the runtime asked to be terminated in an unusual way" errors.
Charles Bailey
Can't the manifest be embedded inside the EXE? Isn't that the default setting in Visual Studio?
AshleysBrain
@AshleysBrain: Yes it can, and by default is but if your exe's manifest references the CRT assembly then that assembly must also be present and complete, including its manifest, and the CRT assembly manifest is an external manifest in VS2005 and VS2008.
Charles Bailey
+1  A: 

If you want the link against the DLL version of the CRT libraries and you want to avoid installing anything then you need to copy every member of the CRT assembly into the same folder as your executable. It may not be the way that Microsoft pushes you towards but it is valid and it does work.

In your Visual Studio 2008 install directory your should find a folder: VC\redist\x86\Microsoft.VC90.CRT. If you copy the complete contents of that folder (including the manifest file) to the same directory as your executable then you should be able to run the executable from that location.

Charles Bailey