静态和共享库之间的区别? [英] Difference between static and shared libraries?

查看:227
本文介绍了静态和共享库之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是静态和共享库之间的区别?

What is the difference between static and shared libraries?

我使用Eclipse有几个项目类型,包括静态库和共享库?做一件有优势比其他?

I use Eclipse and there are several project types including Static Libraries and Shared Libraries? Does one have an advantage over the other?

推荐答案

共享库是。所以(或在Windows .dll或在OS X名为.dylib)文件。与该库中的所有code是在这个文件中,它是由使用它在运行时程序引用。使用共享库的程序只引用了它的共享库使用code。

Shared libraries are .so (or in Windows .dll, or in OS X .dylib) files. All the code relating to the library is in this file, and it is referenced by programs using it at run-time. A program using a shared library only makes reference to the code that it uses in the shared library.

静态库。一个(或Windows的.lib)文件。所有与该库的code是在这个文件中,它直接链接到在编译时的程序。使用静态库的程序需要,它从静态库使用,使得它的计划的一部分code的副本。 [Windows还具有的.lib这是用来引用.dll文件的文件,但他们的行为方式与第一次相同。

Static libraries are .a (or in Windows .lib) files. All the code relating to the library is in this file, and it is directly linked into the program at compile time. A program using a static library takes copies of the code that it uses from the static library and makes it part of the program. [Windows also has .lib files which are used to reference .dll files, but they act the same way as the first one].

有优点和缺点每个方法。

There are advantages and disadvantages in each method.

共享库减少在每个使用了库程序复制了code量,保持二进制代码变得很小。它也可以让你更换一个在功能上等同的共享对象,但可能有增加的性能优势,而无需重新编译,使得使用它的计划。共享库将,但是对功能的执行,以及运行时加载成本一小笔额外成本库中的所有符号需要连接到他们所使用的东西。此外,共享库可装入在运行时应用程序,它是用于实现二进制插件系统的一般机制

Shared libraries reduce the amount of code that is duplicated in each program that makes use of the library, keeping the binaries small. It also allows you to replace the shared object with one that is functionally equivalent, but may have added performance benefits without needing to recompile the program that makes use of it. Shared libraries will, however have a small additional cost for the execution of the functions as well as a run-time loading cost as all the symbols in the library need to be connected to the things they use. Additionally, shared libraries can be loaded into an application at run-time, which is the general mechanism for implementing binary plug-in systems.

静态库增加了二进制的整体大小,但它意味着你不需要沿着正在使用的库的副本携带。由于code在编译时连接没有任何额外的运行时加载的费用。在code是根本没有。

Static libraries increase the overall size of the binary, but it means that you don't need to carry along a copy of the library that is being used. As the code is connected at compile time there are not any additional run-time loading costs. The code is simply there.

我个人preFER共享库,但在需要的时候,以确保二进制文件没有多少外部依赖性可能难以满足,如C的特定版本++标准库或特定版本的使用静态库在Boost C ++库。

Personally, I prefer shared libraries, but use static libraries when needing to ensure that the binary does not have many external dependencies that may be difficult to meet, such as specific versions of the C++ standard library or specific versions of the Boost C++ library.

这篇关于静态和共享库之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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