何时使用动态库与静态库 [英] When to use dynamic vs. static libraries

查看:121
本文介绍了何时使用动态库与静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中创建类库时,可以在动态(.dll)和静态(.lib)库之间进行选择。它们之间有什么区别,什么时候适合使用?

When creating a class library in C++, you can choose between dynamic (.dll) and static (.lib) libraries. What is the difference between them and when is it appropriate to use which?

推荐答案

静态库会增加代码的大小二进制。它们总是加载的,你编译的代码的任何版本都是将运行的代码版本。

Static libraries increase the size of the code in your binary. They're always loaded and whatever version of the code you compiled with is the version of the code that will run.

动态库单独存储和版本化。可能会加载动态库的版本,而不是您的代码随附的原始版本如果,更新被认为是与原始版本的二进制兼容。

Dynamic libraries are stored and versioned separately. It's possible for a version of the dynamic library to be loaded that wasn't the original one that shipped with your code if the update is considered binary compatible with the original version.

另外,动态库不一定加载 - 它们通常在首次调用时加载 - 并且可以在使用相同库的组件之间共享(多个数据加载,一个代码加载)。

Additionally dynamic libraries aren't necessarily loaded -- they're usually loaded when first called -- and can be shared among components that use the same library (multiple data loads, one code load).

动态库在大多数时候被认为是更好的方法,但最初他们有一个主要的缺陷(谷歌DLL地狱),它已被更多的Windows操作系统(特别是Windows XP)。

Dynamic libraries were considered to be the better approach most of the time, but originally they had a major flaw (google DLL hell), which has all but been eliminated by more recent Windows OSes (Windows XP in particular).

这篇关于何时使用动态库与静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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