开发者

Dll vs static lib (MSVC9 RunTime Library option)

开发者 https://www.devze.com 2023-03-22 15:14 出处:网络
For a MSVC9 Win32 project following options are shown under Configuration Properties -> C/C++ -> Code Geberation -> Runtime Library:

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号