ZHOU
ZHOU

Reputation: 1191

How do static .lib files link each other?

For example, if I have a lib A that has dependency on lib B, then do I need to link both lib A and lib B or only lib A, when I write a program C that depends on lib A?

Upvotes: 5

Views: 184

Answers (2)

Static libraries are not linked. Notice that the tool creating a static library is not a linker—it's ar (archiver) on Unix-like platforms and lib (librarian) when using the MS toolchain. This is an important point to remember when dealing with static libraries and linking.

And it should answer your question. Unless the author of A took explicit extra steps to put the contents of B into A, you'll need to link against both A and B.

Upvotes: 5

Nonanon
Nonanon

Reputation: 560

A library (A) that needs another library (B) will link that library to the exe. This is because A doesnt need to know the code in B, only the exe does. This is because in the linking stage, all code in the libraries are effectively copied into the exe, therefore all references to B from A will be resolved at that step.

Upvotes: 1

Related Questions