What's wrong with the way I'm doing this?

I have MS Visual C++ Express 2008 installed on my computer. I have 2 options for linking to the VC++ 9.0 runtime. I can statically link it (embed it into the EXE file) or keep the files external. For simplicity (not needing to have it embedded in every EXE file and DLL file I compile) I have decided to keep it external.

Doing so it still needs a way to refer to the C++ runtime DLLs, so this usually uses a manifest to point it to the correct file. I have intentionally disabled the manifest though (again shrinking the size of the EXE file), and will place the C++ runtime into either the Windows\System32 folder or into the EXE's own folder. My plan is to distribute the C++ runtime separate from the EXE file. A person wanting to use my programs, will only need to download the C++ runtime DLL once, and copy it to the Windows\System32 folder (or alternatively the same folder that contains the EXE file for my program). Then they can download any of my programs, without them being bloated with either a statically linked C++ runtime or a manifest resource in the EXE.

There are 3 files in the C++ 9.0 runtime (msvcr90.dll, msvcp90.dll, and msvcm90.dll). To test my ability to link to the runtime files externally, I have copied all 3 of them to the same folder as my EXE file. I then ran the program.

Unfortunately I'm greeted with the following error message when I run the EXE file.
https://i.imgur.com/o5zZ6sT.png

Can you tell me what I'm doing wrong?
Last edited on
Not sure. My impression though has always been that users need to run some sort of installation program to install the VC Runtime. Because of crap like that I never link /MD. I always statically link necessary routines into my exes to avoid such problems. It does sound like a pathing problem to me.

In terms of the size of exes, I've always considered VC's binaries to be way too big compared to other languages I've used. I wrote a substitute for the VC runtime, i.e., I use the /nodefaultlib switch, and I can put up a window with VC++9 statically linked (/MT) in about 4k.

Maybe post the command line strings being fed into the compiler and linker. You can get them from the various properties windows. Sounds to me like something is wrong there.

Not really an answer, but please note that there is almost never a need to put dlls in System32.

If your program depends on the C++ 9.0 runtime, it looks like that is best to be installed using the "Microsoft Visual C++ 2008 Service Pack 1 Redistributable Package MFC Security Update", downloadable from https://www.microsoft.com/en-us/download/details.aspx?id=26368

But I don't know much more than that.
As for the command line strings, I just use the ones that are accessible to me via VC++2008's GUI settings. I never manually edit the strings.

How do you statically link only "necessary routines into my exes to avoid such problems"? Either the entire VC runtime is linked, or none of it is linked?

I also read somewhere else on the internet that VC++ 2008 (aka VC++9.0) that when using externally linked C runtime DLLs it does not allow them to simply be placed in a normal location (like System32 or the same folder as the EXE), forcing you to instead use an SxS based installation of the runtime DLLs (which requires the installer program).

But from what I read you can use the runtime DLLs the normal way (without special installation) with VC++ 2010 (aka VC++10.0), placing them either in the program's own folder or in the System32 folder. Can anybody here confirm this difference between VC++ 2008 and 2010 to actually be true?
How do you statically link only "necessary routines into my exes to avoid such problems"? Either the entire VC runtime is linked, or none of it is linked?
Note that freddie1 did not say "statically link only the necessary routines". He said "statically link necessary routines". In other words, to link statically everything you need, even if to do that you have to link statically things you don't need.
The only thing else I can add, is that a long time ago I created an exe using VStudio 2008 (VC15) and it was a /MD linked binary. When I tried to run it on a Win 2000 box it wouldn't run (It wasn't possible to install VStudio 2008 on Win 2000. VStudio 2008 came out around Windows Vista time). In other words, the runtime dependencies weren't there for it to run. If I recall I copied those several runtime dependency files you mentioned from the System32 directory of the newer box and put them on the Win 2000 box, and the files ran fine. I didn't run any setup program to do it. I just copied them. It was a long time ago so I'm not 100% certain where I put them on the Win 2000 box, but if I had to make a guess, if I got them out of /System32 on one computer, its likely that's where I put them on the other. Whether or not the newer OSs allow that I'm not sure. I expect so if running as administrator.
I never had VS 2008 installed, only VS6, 2015 and 2017, but if it is laid out similarly there should be installation files for the C/C++ runtime libraries that can be redistibuted with your program. Usually run as part of a scripted installation.
Last edited on
Registered users can post here. Sign in or register to post.