# New to VS2008: How do I compile static and distribute?

This topic is 3417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all, I'm quite new to VS2008 so please bear with me. I've created a new solution and added two projects. The first one is a library needed by the second project. Both compile just fine and run just fine, except when I move the .exe and the .dll into another location on my machine or move to another machine. The OS complains about not being able to find MSVCR90.dll. Why do I need this .DLL? Will I have to install this .DLL on every single machine I want to distribute my app to? I know about that VS2008 Redistributable Package thing and it is quite unacceptable/unrealistic to have that as a requirement. How can I, basically, compile everything I need into this one .exe? On linux this is called static linking. There are hundreds, if not thousands, of other C-based apps written for Windows that don't require this special .DLL so why does mine? Many thanks!

##### Share on other sites
You need it because you compiled the program with Visual Studio, that's one of the downsides to using it; you need special runtime libraries.

You cannot statically link them as 1) they are not available as static libraries and 2) even if they were it would be against Microsoft's license (not 100% sure about this one though).

Edit: Ignore my post

##### Share on other sites
You can statically link using the /MT switch (forum thread) though creating an installer and bundling the VC++2008 runtime redistributable is probably a better idea.

##### Share on other sites
@Homersp: Absolute nonsense!

They are available as static libraries and you are allowed to ship the static runtime with your executables/dlls. The question is whether you want to.

To switch the the static runtime, open project settings, go to C/C++, then to "Code Generation" and switch the runtime to "Multithreaded" for your "Release" configuration and to "Multithreaded Debug" for your "Debug" configuration.

Please be aware that, when using DLLs and the static runtime, each binary is responsible for its own heap. That means you can no longer allocate memory in the DLL and free it in the EXE and vice versa (using it across the boundary is fine, of course). There have been several discussions here on gamedev.net that can provide further informations.

##### Share on other sites
It's because you dynamically linked to the CRT. You can statically link to it, but that is usually shunned because of the way the CRT manages its memory. You can statically link to it by going to Project->Project Properties->Configureation Properties->C/C++->Code Generation and changing "Runtime Library" to one of the options without the word "DLL" in it. This is usually just fine for smaller projects, but for larger ones you should dynamically link to the CRT and use this deployment guide to package your program with the VS2008 CRT.

OMG ninja'd += 3!

##### Share on other sites
Hi guys,
Thanks for the wealth of replies.

benryves: I tried the /MT switch and I still get the error. It doesn't seem to honor what I told it to do.

HomerSp: Didn't realize that using VS2008 to compile forces me to use it's libraries (God I hate M$). Think I'll try this with Eclipse or just use gcc from the command line. All Others: This app is technically an addon to an existing application that has it's own methods of distributing addon's to other servers. Thus I cannot run an installer from within. I can only tell it "these are the files needed to run". I wouldn't mind distributing the app + 2 or 3 .dll's as long as that is all I need for it to run on any WinXP or Win2K3 machine. Thanks! #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by utdrmacbenryves: I tried the /MT switch and I still get the error. It doesn't seem to honor what I told it to do. Did you definitely change the Release configuration? And did you change the setting in Project Settings (Alt+F7) -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library to "Multi-threaded (/MT)"? If not, I'd definitely use that method. Quote:  Original post by utdrmacHomerSp: Didn't realize that using VS2008 to compile forces me to use it's libraries (God I hate M$). Think I'll try this with Eclipse or just use gcc from the command line.
GCC will do the same thing, it probably just defaults to static linking (If it even has a dynamic linking option) - which has it's own problems.
There's been quite a few threads here (Have a look on Google) about why it's a good thing to use the DLL versions (Anything that's heavily plugin based would be absolutely massive, and might not even fit in a 32-bit address space for one, you can't pass FILE* pointers or other CRT objects between statically applications and DLLs build with a static CRT version, and any security problems in the CRT can be patched via Windows Update.
Aside: Please don't use "M$", it just makes you sound like an idiot - "lulz M$ si teh sux! Linux0rz for teh win!!1"

Quote:
 Original post by utdrmacAll Others: This app is technically an addon to an existing application that has it's own methods of distributing addon's to other servers. Thus I cannot run an installer from within. I can only tell it "these are the files needed to run".I wouldn't mind distributing the app + 2 or 3 .dll's as long as that is all I need for it to run on any WinXP or Win2K3 machine.
You can't legally distribute those DLLs on their own because that would make them impossible to patch from Windows Update (for security problems).

If you absolutely can't provide an installer or get the user to download the redist package, then static linking to the CRT is the only real option.

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by utdrmacHomerSp: Didn't realize that using VS2008 to compile forces me to use it's libraries (God I hate M\$). Think I'll try this with Eclipse or just use gcc from the command line.
GCC will do the same thing, it probably just defaults to static linking (If it even has a dynamic linking option) - which has it's own problems.

It depends on which version of gcc you're talking about. The MinGW native port, for example, actually generates a dependency on the Microsoft Visual C++ runtime DLL (Version 6, IIRC).

##### Share on other sites
EvilSteve: Yes, I'm positive I changed to Release and I'm positive I changed to /MT. It doesn't work as expected.

I guess I'll have to get with the developers of the system we are using then because they have developed around 50 of these addons all using VS2008 and none of them require these special .DLL's to be installed on host machines with their addon packages.

Thanks all!

• 9
• 13
• 40
• 15
• 11