Dll vs static lib (MSVC9 RunTime Library option)

2019-06-06 03:15发布

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条回答
2楼-- · 2019-06-06 04:01

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.

查看更多
登录 后发表回答