Dll vs static lib (MSVC9 RunTime Library option)

你离开我真会死。 提交于 2019-12-10 10:29:43

问题


For a MSVC9 Win32 project following options are shown under Configuration Properties -> C/C++ -> Code Geberation -> Runtime Library:

/MT, /MTd, /MD, /MDd

is it correct that for a DLL /MTd should be used and for static lib /MDd?

Thanks.


回答1:


There are two issues that are at play here.

First, you need to choose if you want the Debug version of the CRT or the Release version. The debug versions have special checks and code paths designed to help you catch bugs while writing an application. You should not use them for the final release version of an application because they can slow down its execution, and because they are not freely redistributable.

Then, you need to decide if you want to statically link the run-time to your application, or if you want to use it dynamically from a DLL. Static linking allows you to create a standalone EXE file with no dependencies on any DLL files; it effectively compiles the run-time code into your application's binary. This can make deployment easier, but it comes at the cost of not being able to take advantage of security and other updates that are made to the run-time DLLs. You'll have to recompile your application in order to take advantage of the new run-time updates. Dynamic linking is the typical (and recommended) path for Windows applications. It means that your application will require the appropriate versions of the CRT DLLs to be present in order for it to run, but it allows the run-time libraries to be easily updated and means that multiple programs can share the same code, reducing their size on disk.

So, /MD means dynamically-linked and /MT means statically-linked. The lower-case d after each option indicates that the debug version of the run-time libraries is used.

/MD = dynamically-linked to release (redistributable) version of CRT

/MDd = dynamically-linked to debug (non-redistributable) version of CRT

/MT = statically-linked to release (redistributable) version of CRT

/MTd = statically-linked to debug (non-redistributable) version of CRT

More information is available on MSDN.



来源:https://stackoverflow.com/questions/6799237/dll-vs-static-lib-msvc9-runtime-library-option

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