Which VC++ runtime version do I choose - static or dynamic?

家住魔仙堡 提交于 2020-01-04 05:05:00

问题


I'm developing a 64-bit in-proc VC++ ATL COM server that basically just redirects all calls to an out-proc COM server. So my COM server basically does nothing.

Initially it used the C++ runtime in a DLL (/MD compiler switch). I've noticed that when I deploy it on a clean 64-bit Win2k3 regsvr32 fails with an error: LoadLibrary({fileName}) failed – This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

Google helps - the problem is that VC++9 runtime is not installed. The problem persists even when msvcr90.dll is in the same directory as my COM server. That as I guess is because of how search for dependent libraries works - it doen't look into the same directory and I need the msvcr90.dll in Windows\System32 or the like. Since this is a complication to my deployment I switched to using the statically linked C++ runtime (/MT compiler switch). Now it deploys fine. The size of the .dll file is 110k only (was 45k) so it doesn't bother me.

Now I've heard a lot about how bad it is to mix different versions of C++ runtime in one process - CRT state can be broken, hell can break loose and so on. Do I have to think of this and expect problems from changing /MD to /MT especially since I don't know what version the COM server consumers are using?


回答1:


As far as I know the Static runtime is deprecated in VS since VS2005.

The problem is that the Visual C Runtime is a side by side dll. That is it must be loaded from the c:\windows\winsxs directory. This is why placing it in the same directory is no longer works.

The correct solution is to install the correct CRT redistributable on the client system.

See http://msdn.microsoft.com/en-us/library/ms235316.aspx for more information

This might be the correct redistributable: http://www.microsoft.com/downloads/details.aspx?familyid=BD2A6171-E2D6-4230-B809-9A8D7548C1B6&displaylang=en

Installing the correct one will place the runtime dlls in the winsxs directory.




回答2:


It should not be a problem.

The static linking basically takes the required functions from a library and puts them into the code of your DLL (thus the increase in size). It should then work just the same as if you wrote those functions in your code yourself.



来源:https://stackoverflow.com/questions/1706762/which-vc-runtime-version-do-i-choose-static-or-dynamic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!