For faster navigation, this Iframe is preloading the Wikiwand page for 库.
库(英语:library)是在电脑科学中用于开发软件的子程序集合。库和可执行文件的区别是,它不是独立的电脑程序,而是向其他程序提供服务的代码。
链接
库链接(英语:linking)是指把一个或多个库包括到程序中,有两种链接形式:静态链接和动态链接;相应的,前者链接的库叫做静态库,后者的叫做动态库。
静态库
静态链接是由链接器在链接时将库的内容加入到可执行程序中的做法。链接器是一个独立程序,将一个或多个库或目标文件(先前由编译器或汇编器生成)链接到一块,以生成可执行程序。
静态链接的最大缺点是生成的可执行文件较大,需要更多的系统资源,在加载到存储器时也会消耗更多的时间。
共享库
动态库
动态链接是在可执行文件装载时或运行时,由操作系统的装载程序加载库。大多数操作系统将解析外部引用(比如库)作为加载过程的一部分。在这些系统上,可执行文件包含一个叫做导入目录(import directory)的表,该表的每一项包含一个库的名字。根据表中记录的名字,装载程序在硬盘上搜索需要的库,然后将其加载到内存中预先不确定的位置,之后根据加载库后确定的库的地址更新可执行程序。可执行程序根据更新后的库信息调用库中的函数或引用库中的数据。这种类型的动态加载称为装载(load-time)时加载,被包括Windows和Linux的大多数系统采用。装载程序在加载应用软件时要完成的最复杂的工作之一就是加载时链接。
其他操作系统可能在运行时解析引用。在这些系统上,可执行程序调用操作系统API将库的名字、函数在库中的编号和函数参数一同传递。操作系统负责立即解析然后代表应用调用合适的函数。这种动态链接叫做运行时链接。因为每个调用都会有系统开销,运行时链接要慢得多,对应用的性能有负面影响。现代操作系统已经很少使用运行时链接。
可以动态链接的库,在Windows上是Dynamic Link Library(DLL),在UNIX或Linux上是Shared Library。库文件是预先编译链接好的可执行文件,存储在电脑的硬盘上。大多数情况下,同一时间多个应用可以使用一个库的同一份拷贝,操作系统不需要加载这个库的多个实例。
{{bottomLinkPreText}}
{{bottomLinkText}}
This page is based on a Wikipedia article written by
contributors (read/edit).
Text is available under the
CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.
{{current.index+1}} of {{items.length}}
Thanks for reporting this video!
This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:
An extension you use may be preventing Wikiwand articles from loading properly.
If you're using HTTPS Everywhere or you're unable to access any article on Wikiwand, please consider switching to HTTPS (https://www.wikiwand.com).
An extension you use may be preventing Wikiwand articles from loading properly.
If you are using an Ad-Blocker, it might have mistakenly blocked our content.
You will need to temporarily disable your Ad-blocker to view this page.
✕
This article was just edited, click to reload
Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}
Follow Us
Don't forget to rate us
Oh no, there's been an error
Please help us solve this error by emailing us at
support@wikiwand.com
Let us know what you've done that caused this error, what browser you're using, and whether you have any special extensions/add-ons installed.
Thank you!