DLL vs静态库(MSVC9运行时库选项) [英] Dll vs static lib (MSVC9 RunTime Library option)

查看:210
本文介绍了DLL vs静态库(MSVC9运行时库选项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MSVC9 Win32项目,在配置属性-> C/C ++->代码解放->运行时库下显示以下选项:

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

/MT,/MTd,/MD,/MDd

/MT, /MTd, /MD, /MDd

对于DLL/MTd应该使用静态lib/MDd是否正确?

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

谢谢.

推荐答案

这里有两个问题.

首先,您需要选择要使用CRT的 Debug 版本还是 Release 版本.调试版本具有特殊的检查和代码路径,旨在帮助您在编写应用程序时捕获错误.您不应不要将它们用于应用程序的最终发行版,因为它们会减慢其执行速度,并且不能自由重新分发.

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.

然后,您需要确定是否要静态将运行时链接到应用程序,或者是否要从DLL中动态使用它.静态链接使您可以创建一个独立的EXE文件,而该文件不依赖于任何DLL文件.它可以将运行时代码有效地编译到应用程序的二进制文件中.这可以使部署更容易,但是却以无法利用对运行时DLL进行的安全性和其他更新为代价.您必须重新编译您的应用程序才能利用新的运行时更新.动态链接是Windows应用程序的典型(推荐的)路径.这意味着您的应用程序将需要提供适当版本的CRT DLL才能运行,但是它允许轻松地更新运行时库,并且意味着多个程序可以共享同一代码,从而减小了程序的大小.在磁盘上.

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.

因此,/MD表示动态链接,而/MT表示静态链接.每个选项后的小写字母d表示使用了运行时库的 debug 版本.

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 =动态链接到发行(可再发行)的CRT版本

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

/MDd =动态链接到调试(不可分发)的CRT版本

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

/MT =静态链接到发行(可再发行)的CRT版本

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

/MTd =静态链接到调试(不可分发)的CRT版本

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

有关更多信息,请访问 MSDN .

More information is available on MSDN.

这篇关于DLL vs静态库(MSVC9运行时库选项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆