库相对于目标文件的好处

The benefit of libraries over object files

我一直在阅读有关 linux 库的主题 http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html

它提到:

"The benefit is that each and every object file need not be stated when linking because the developer can reference the individual library"

我不遵守这个声明。我想知道是否有人可以提供进一步的解释或示例?

谢谢

这不是世界上最好的措辞,IIUC,并且有点误导。恕我直言,而不是

The benefit is that each and every object file need not be stated when linking because the developer can reference the individual library

应该是

The benefit is that each and every object file need not be stated when linking because the developer can reference the entire library (as a named entity)

基本上就是下面的意思。在没有库的情况下,现在是库的作者可以简单地构建一个目标文件列表,如下所示:

a0.cpp -> a0.o
a1.cpp -> a1.o
...

然后她可以在文档中写"if you want functions x, y, and z",然后你需要link和a3.o(因为它包含x和z),a42.o(因为y),还有 a23.o、a15.o 和 a72.o,因为它们包含必要的基础部分。

这当然很笨重。正如您的 link 所解释的,一种更明智的方法是从通用功能和 类 的状态创建一个库。指令变为 "if you want the functionality of shooting up foo aliens, link with the foo_alien_shooting library".