你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下lib详细说明

lib类型

[日期:2007-06-03] 来源:Linux公社  作者:Linux [字体: ]
一、lib类型:
与windows下静态库(.lib)和动态库(.dll)一样,linux同样存在静态库(static library 文件后缀为.a)和共享库(shared library 文件后缀为.so),在/usr/lib目录下同时存在一个库的静态版本和动态版本。

"An archive (or static library) is simply a collection of object files stored as a single file.When you provide an archive to the linker, the linker searches the archive for the object files it needs, extracts them, and links them into your program much as if you had provided thoseobject files directly."

"A shared library is similar to a archive in that it is a grouping of object files. However, there are many important differences.The most fundamental difference is that when a shared library islinked into a program, the final executable does not actually contain the code that ispresent in the shared library. Instead, the executable merely contains a reference to theshared library."

"the object files that compose the shared library are combined into asingle object file so that a program that links against a shared library always includes allof the code in the library, rather than just those portions that are needed."

以上引自《Advanced Linux Programming》

由此可知,静态库和共享库都是一个obj文件的集合,但静态链接后,执行程序中存在自己所需obj的一份拷贝,而动态链接后,执行程序仅仅是包含对共享库的一个引用。共享库相当于一个由多个obj文件组合而成的obj文件,在链接后其所有代码被加载,不管需要的还是不需要的。

似乎可以得出一个结论:
静态链接后的程序比动态链接的所用存储空间大,因为执行程序中包含了库中代码拷贝;而动态链接的程序比静态链接的所用的运行空间大,因为它将不需要的代码也加载到运行空间。linux
【内容导航】
第1页:lib类型 第2页:lib编译
第3页:lib调用 第4页:lib相关说明
相关资讯       lib 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款